From 7a667abc73e16f30119f6233944b4553799c87db Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Mon, 31 Jan 2011 15:09:01 -0800 Subject: [PATCH] unread true on notification receive --- app/models/notification.rb | 5 +++-- spec/models/notification_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 514d3afea..7f2e5a182 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -12,7 +12,7 @@ class Notification < ActiveRecord::Base belongs_to :target, :polymorphic => true def self.for(recipient, opts={}) - self.where(opts.merge!(:recipient_id => recipient.id)).order('created_at desc') + self.where(opts.merge!(:recipient_id => recipient.id)).order('updated_at desc') end def self.notify(recipient, target, actor) @@ -50,8 +50,9 @@ private :recipient_id => recipient.id).first unless n.actors.include?(actor) n.actors << actor - n.save! end + n.unread = true + n.save! n else make_notification(recipient, target, actor, action) diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index aaf1837c0..e8ececfb0 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -99,6 +99,16 @@ describe Notification do Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => @sm)).receive_object Notification.where(:recipient_id => @user3.id,:target_id => @sm.id).first.actors.count.should == 2 end + + it 'marks the notification as unread' do + note = Notification.where(:recipient_id => @user3.id,:target_id => @sm.id).first + note.unread = false + note.save + lambda { + Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :on => @sm)).receive_object + note.reload + }.should change(note, :unread).from(false).to(true) + end end end end