fix notifications controller. yay.

This commit is contained in:
danielgrippi 2012-02-14 15:59:51 -08:00
parent 52c8540091
commit a5debd795d

View file

@ -5,12 +5,8 @@
require 'spec_helper' require 'spec_helper'
describe NotificationsController do describe NotificationsController do
render_views(false)
before do before do
@user = alice sign_in :user, alice
@aspect = @user.aspects.first
@controller = NotificationsController.new
@controller.stub!(:current_user).and_return(@user)
end end
describe '#update' do describe '#update' do
@ -37,7 +33,7 @@ describe NotificationsController do
it 'only lets you read your own notifications' do it 'only lets you read your own notifications' do
user2 = bob user2 = bob
Factory(:notification, :recipient => @user) Factory(:notification, :recipient => alice)
note = Factory(:notification, :recipient => user2) note = Factory(:notification, :recipient => user2)
get :update, "id" => note.id, :set_unread => "false" get :update, "id" => note.id, :set_unread => "false"
@ -49,20 +45,20 @@ describe NotificationsController do
describe "#read_all" do describe "#read_all" do
it 'marks all notifications as read' do it 'marks all notifications as read' do
request.env["HTTP_REFERER"] = "I wish I were spelled right" request.env["HTTP_REFERER"] = "I wish I were spelled right"
Factory(:notification, :recipient => @user) Factory(:notification, :recipient => alice)
Factory(:notification, :recipient => @user) Factory(:notification, :recipient => alice)
Notification.where(:unread => true).count.should == 2 Notification.where(:unread => true).count.should == 2
get :read_all get :read_all
Notification.where(:unread => true).count.should == 0 Notification.where(:unread => true).count.should == 0
end end
it "should redirect to the stream in the html version" do it "should redirect to the stream in the html version" do
Factory(:notification, :recipient => @user) Factory(:notification, :recipient => alice)
get :read_all, :format => :html get :read_all, :format => :html
response.should redirect_to(stream_path) response.should redirect_to(stream_path)
end end
it "should return a dummy value in the json version" do it "should return a dummy value in the json version" do
Factory(:notification, :recipient => @user) Factory(:notification, :recipient => alice)
get :read_all, :format => :json get :read_all, :format => :json
response.should_not be_redirect response.should_not be_redirect
end end
@ -71,11 +67,11 @@ describe NotificationsController do
describe '#index' do describe '#index' do
before do before do
@post = Factory(:status_message) @post = Factory(:status_message)
Factory(:notification, :recipient => @user, :target => @post) Factory(:notification, :recipient => alice, :target => @post)
end end
it 'paginates the notifications' do it 'paginates the notifications' do
25.times { Factory(:notification, :recipient => @user, :target => @post) } 25.times { Factory(:notification, :recipient => alice, :target => @post) }
get :index get :index
assigns[:notifications].count.should == 25 assigns[:notifications].count.should == 25
get :index, "page" => 2 get :index, "page" => 2
@ -83,20 +79,20 @@ describe NotificationsController do
end end
it "supports a limit per_page parameter" do it "supports a limit per_page parameter" do
5.times { Factory(:notification, :recipient => @user, :target => @post) } 5.times { Factory(:notification, :recipient => alice, :target => @post) }
get :index, "per_page" => 5 get :index, "per_page" => 5
assigns[:notifications].count.should == 5 assigns[:notifications].count.should == 5
end end
describe "special case for start sharing notifications" do describe "special case for start sharing notifications" do
it "should not provide a contacts menu for standard notifications" do it "should not provide a contacts menu for standard notifications" do
2.times { Factory(:notification, :recipient => @user, :target => @post) } 2.times { Factory(:notification, :recipient => alice, :target => @post) }
get :index, "per_page" => 5 get :index, "per_page" => 5
Nokogiri(response.body).css('.aspect_membership').should be_empty Nokogiri(response.body).css('.aspect_membership').should be_empty
end end
it "should provide a contacts menu for start sharing notifications" do it "should provide a contacts menu for start sharing notifications" do
2.times { Factory(:notification, :recipient => @user, :target => @post) } 2.times { Factory(:notification, :recipient => alice, :target => @post) }
eve.share_with(alice.person, eve.aspects.first) eve.share_with(alice.person, eve.aspects.first)
get :index, "per_page" => 5 get :index, "per_page" => 5