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