diff --git a/app/models/notification.rb b/app/models/notification.rb index dd71884e5..887922894 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -14,5 +14,10 @@ class Notification timestamps! - attr_accessible :object_id, :kind, :user, :person + attr_accessible :object_id, :kind, :user_id, :person_id + + def for(user, opts={}) + query = opts.merge(:user_id => user) + self.all(opts) + end end diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index e3d93cdb1..1c831b7f6 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -64,6 +64,9 @@ module Diaspora end def receive_object(object,person) + unless object.is_a? Retraction + Notification.create(:object_id => object.id, :kind => object.class.name, :person_id => person.id, :user_id => self.id) + end if object.is_a?(Request) receive_request object, person elsif object.is_a?(Profile) diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index d74333965..35bfb7b25 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -11,7 +11,6 @@ describe Notification do @person = Factory(:person) @user = make_user @note = Notification.new(:object_id => @sm.id, :kind => @sm.class.name, :person => @person, :user => @user) - puts @note.inspect end it 'contains a type' do @@ -25,5 +24,9 @@ describe Notification do it 'contains a person_id' do @note.person.id == @person.id end + + describe '.for' do + end + end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 50b7dba70..86ac26b38 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -60,10 +60,12 @@ describe User do describe '#receive_object' do it 'adds a notification for an object' do - Notification.should_receive(:new) + Notification.should_receive(:create) user = make_user - user.receive_object(Factory(:status_message), Factory(:person)) + sm = Factory.create(:status_message) + person = Factory.create(:person) user.should_receive(:receive_post).and_return(true) + user.receive_object(sm, person) end end