unread true on notification receive

This commit is contained in:
zhitomirskiyi 2011-01-31 15:09:01 -08:00
parent d6ab633e2c
commit 7a667abc73
2 changed files with 13 additions and 2 deletions

View file

@ -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)

View file

@ -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