diff --git a/app/models/notification.rb b/app/models/notification.rb index b1431cffd..4c86f6a93 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -54,7 +54,7 @@ private unless n.actors.include?(actor) n.actors << actor end - + n.unread = true n.save! n @@ -68,6 +68,7 @@ private :action => action, :recipient_id => recipient.id) n.actors << actor + n.unread = false if target.is_a? Request n.save! n end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 17f7d221a..56ed2269a 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -22,7 +22,7 @@ describe Notification do it 'destoys the associated notification_actor' do @note.save - lambda{@note.destroy}.should change(NotificationActor, :count).by(-1) + lambda{@note.destroy}.should change(NotificationActor, :count).by(-1) end describe '.for' do @@ -53,6 +53,11 @@ describe Notification do Notification.notify(@user, @request, @person) end + it 'creates the notification already read' do + n = Notification.notify(@user, @request, @person) + n.unread?.should be_false + end + it 'sockets to the recipient' do opts = {:target_id => @request.id, :target_type => "Request", @@ -94,7 +99,7 @@ describe Notification do it "updates the notification with a more people if one already exists" do Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2 end - + it 'handles double comments from the same person without raising' do Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => @sm)).receive_object Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2