create a new notifciation if previous was read, only concatinate when it is the same unread message

This commit is contained in:
Maxwell Salzberg 2011-05-02 18:18:30 -07:00
parent c41acbabd6
commit c20cd5381e
2 changed files with 13 additions and 11 deletions

View file

@ -41,7 +41,8 @@ private
def self.concatenate_or_create(recipient, target, actor, notification_type)
if n = notification_type.where(:target_id => target.id,
:target_type => target.class.base_class,
:recipient_id => recipient.id).first
:recipient_id => recipient.id,
:unread => true).first
unless n.actors.include?(actor)
n.actors << actor
end

View file

@ -12,11 +12,12 @@ describe Notification do
@user2 = eve
@aspect = @user.aspects.create(:name => "dudes")
@opts = {:target_id => @sm.id,
:target_type => @sm.class.name,
:target_type => @sm.class.base_class.to_s,
:type => 'Notifications::CommentOnPost',
:actors => [@person],
:recipient_id => @user.id}
@note = Notification.new(@opts)
@note.type = 'Notifications::CommentOnPost'
@note.actors =[ @person]
end
@ -39,6 +40,15 @@ describe Notification do
end
end
describe '.concatenate_or_create' do
it 'creates a new notificiation if the notification does not exist, or if it is unread' do
@note.unread = false
@note.save
Notification.count.should == 1
Notification.concatenate_or_create(@note.recipient, @note.target, @note.actors.first, Notifications::CommentOnPost)
Notification.count.should == 2
end
end
describe '.notify' do
it 'does not call Notification.create if the object does not have a notification_type' do
Notification.should_not_receive(:make_notificatin)
@ -104,15 +114,6 @@ describe Notification do
Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :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_type => @sm.class.base_class, :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