Fix build - stub request in notifications#index specs

This commit is contained in:
Sarah Mei 2011-07-03 20:48:42 -07:00
parent 511a651377
commit 58ac33607a

View file

@ -48,26 +48,45 @@ describe NotificationsController do
before do
@post = Factory(:status_message)
Factory(:notification, :recipient => @user, :target => @post)
@fake_request = ActionDispatch::Request.new({})
@controller.stub!(:request).and_return(@fake_request)
end
it 'paginates the notifications' do
25.times do
Factory(:notification, :recipient => @user, :target => @post)
context "html request" do
before do
@fake_request.stub!(:format).and_return(:html)
end
@controller.index({})[:notifications].count.should == 25
@controller.index(:page => 2)[:notifications].count.should == 1
it 'paginates the notifications' do
25.times { Factory(:notification, :recipient => @user, :target => @post) }
@controller.index({})[:notifications].count.should == 25
@controller.index(:page => 2)[:notifications].count.should == 1
end
it "includes the actors" do
Factory(:notification, :recipient => @user, :target => @post)
response = @controller.index({})
response[:notifications].first[:actors].first.should be_a(Person)
end
it 'eager loads the target' do
response = @controller.index({})
response[:notifications].each { |note| note[:target].should be }
end
end
it "includes the actors" do
notification = Factory(:notification, :recipient => @user, :target => @post)
response = @controller.index({})
response[:notifications].first[:actors].first.should be_a(Person)
end
context "json request" do
before do
@fake_request.stub!(:format).and_return(:json)
end
it 'eager loads the target' do
response = @controller.index({})
response[:notifications].each{ |note| note[:target].should be }
it "returns just the first 5 notifications" do
5.times { Factory(:notification, :recipient => @user, :target => @post) }
response = @controller.index({})
response[:notifications].length.should == 5
end
end
end
end