unread true on notification receive
This commit is contained in:
parent
d6ab633e2c
commit
7a667abc73
2 changed files with 13 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue