« ...OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTest.php » n'existait pas sur « bcf12baf6307283e9895b8bf0567d5bc21a08c9f »
Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe NotificationsController do
before do
it 'marks a notification as read if it gets no other information' do
note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( true )
get :update, "id" => note.id, :format => :json
end
it 'marks a notification as read if it is told to' do
note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( true )
get :update, "id" => note.id, :set_unread => "false", :format => :json
end
it 'marks a notification as unread if it is told to' do
note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( false )
get :update, "id" => note.id, :set_unread => "true", :format => :json
Steven Fuchs
a validé
FactoryGirl.create(:notification, :recipient => alice)
note = FactoryGirl.create(:notification, :recipient => user2)
get :update, "id" => note.id, :set_unread => "false", :format => :json
Notification.find(note.id).unread.should == true
Raphael Sofaer
a validé
before do
@post = FactoryGirl.create(:status_message)
FactoryGirl.create(:notification, :recipient => alice, :target => @post)
Raphael Sofaer
a validé
end
it 'succeeds' do
get :index
response.should be_success
assigns[:notifications].count.should == 1
end
it 'succeeds for notification dropdown' do
get :index, :format => :json
response.should be_success
response.body.should =~ /note_html/
end
it 'succeeds on mobile' do
get :index, :format => :mobile
response.should be_success
end
it 'paginates the notifications' do
25.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
Steven Fuchs
a validé
get :index
assigns[:notifications].count.should == 25
get :index, "page" => 2
assigns[:notifications].count.should == 1
Raphael Sofaer
a validé
it "supports a limit per_page parameter" do
5.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
Steven Fuchs
a validé
get :index, "per_page" => 5
assigns[:notifications].count.should == 5
Raphael Sofaer
a validé
end
describe "special case for start sharing notifications" do
it "should not provide a contacts menu for standard notifications" do
2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
get :index, "per_page" => 5
Nokogiri(response.body).css('.aspect_membership').should be_empty
end
it "should provide a contacts menu for start sharing notifications" do
2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
eve.share_with(alice.person, eve.aspects.first)
get :index, "per_page" => 5
Nokogiri(response.body).css('.aspect_membership').should_not be_empty
end
end
describe "filter notifications" do
it "supports filtering by notification type" do
eve.share_with(alice.person, eve.aspects.first)
get :index, "type" => "started_sharing"
assigns[:notifications].count.should == 1
end
it "supports filtering by read/unread" do
get :read_all
2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
get :index, "show" => "unread"
assigns[:notifications].count.should == 2
end
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
describe "#read_all" do
it 'marks all notifications as read' do
request.env["HTTP_REFERER"] = "I wish I were spelled right"
FactoryGirl.create(:notification, :recipient => alice)
FactoryGirl.create(:notification, :recipient => alice)
Notification.where(:unread => true).count.should == 2
get :read_all
Notification.where(:unread => true).count.should == 0
end
it 'marks all notifications in the current filter as read' do
request.env["HTTP_REFERER"] = "I wish I were spelled right"
FactoryGirl.create(:notification, :recipient => alice)
eve.share_with(alice.person, eve.aspects.first)
Notification.where(:unread => true).count.should == 2
get :read_all, "type" => "started_sharing"
Notification.where(:unread => true).count.should == 1
end
it "should redirect back in the html version if it has > 0 notifications" do
FactoryGirl.create(:notification, :recipient => alice)
eve.share_with(alice.person, eve.aspects.first)
get :read_all, :format => :html, "type" => "started_sharing"
response.should redirect_to(notifications_path)
end
it "should redirect back in the mobile version if it has > 0 notifications" do
FactoryGirl.create(:notification, :recipient => alice)
eve.share_with(alice.person, eve.aspects.first)
get :read_all, :format => :mobile, "type" => "started_sharing"
response.should redirect_to(notifications_path)
end
it "should redirect to stream in the html version if it has 0 notifications" do
FactoryGirl.create(:notification, :recipient => alice)
get :read_all, :format => :html
response.should redirect_to(stream_path)
end
it "should redirect back in the mobile version if it has 0 notifications" do
FactoryGirl.create(:notification, :recipient => alice)
get :read_all, :format => :mobile
response.should redirect_to(stream_path)
end
it "should return a dummy value in the json version" do
FactoryGirl.create(:notification, :recipient => alice)
get :read_all, :format => :json
response.should_not be_redirect
end
end