diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 524edeac5..c9627adc8 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -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