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,19 +48,25 @@ 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
context "html request" do
before do
@fake_request.stub!(:format).and_return(:html)
end end
it 'paginates the notifications' do it 'paginates the notifications' do
25.times do 25.times { Factory(:notification, :recipient => @user, :target => @post) }
Factory(:notification, :recipient => @user, :target => @post)
end
@controller.index({})[:notifications].count.should == 25 @controller.index({})[:notifications].count.should == 25
@controller.index(:page => 2)[:notifications].count.should == 1 @controller.index(:page => 2)[:notifications].count.should == 1
end end
it "includes the actors" do it "includes the actors" do
notification = Factory(:notification, :recipient => @user, :target => @post) Factory(:notification, :recipient => @user, :target => @post)
response = @controller.index({}) response = @controller.index({})
response[:notifications].first[:actors].first.should be_a(Person) response[:notifications].first[:actors].first.should be_a(Person)
end end
@ -70,4 +76,17 @@ describe NotificationsController do
response[:notifications].each { |note| note[:target].should be } response[:notifications].each { |note| note[:target].should be }
end end
end end
context "json request" do
before do
@fake_request.stub!(:format).and_return(:json)
end
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 end