diff --git a/app/models/person.rb b/app/models/person.rb index 742f8b4e4..66b5ca459 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -186,6 +186,6 @@ class Person < ActiveRecord::Base Post.where(:person_id => id).delete_all Comment.where(:person_id => id).delete_all Contact.where(:person_id => id).delete_all - Notification.where(:actors => self).delete_all + Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy} end end diff --git a/spec/factories.rb b/spec/factories.rb index 86a449acc..cf3fd93c6 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -91,7 +91,7 @@ end Factory.define(:notification) do |n| n.association :recipient, :factory => :user - n.association :actor, :factory => :person + n.association :actors, :factory => :person n.association :target, :factory => :comment n.after_build do |note| note.action = note.target.notification_type(note.recipient, note.actor) diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 61af92feb..e6b44b516 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -33,6 +33,11 @@ describe Notification do @note.associations[:people].type.should == :many end + it 'destoys the associated notification_actor' do + @note.save + lambda{@note.destroy}.should change(NotificationActors, :count).by(-1) + end + describe '.for' do it 'returns all of a users notifications' do user2 = Factory.create(:user)