Destroy notifications on contact destroy

This commit is contained in:
Raphael Sofaer 2011-05-23 18:33:06 -07:00
parent e28ec16781
commit 609439f948
3 changed files with 21 additions and 6 deletions

View file

@ -27,6 +27,14 @@ class Contact < ActiveRecord::Base
where(:receiving => true)
}
before_destroy :destroy_notifications
def destroy_notifications
Notification.where(:target_type => "Person",
:target_id => person_id,
:recipient_id => user_id,
:type => "Notifications::StartedSharing").delete_all
end
def dispatch_request
request = self.generate_request
Postzord::Dispatch.new(self.user, request).post

View file

@ -18,7 +18,7 @@ module Diaspora
if notification = Notification.where(:target_id => person.id).first
notification.update_attributes(:unread=>false)
end
contact
end
@ -44,7 +44,7 @@ module Diaspora
retraction = Retraction.for(self)
retraction.subscribers = [person]#HAX
Postzord::Dispatch.new(self, retraction).post
AspectMembership.where(:contact_id => bad_contact.id).delete_all
remove_contact(bad_contact)
end

View file

@ -39,6 +39,13 @@ describe Diaspora::UserModules::Connecting do
bob.should_receive(:remove_contact).with(bob.contact_for(alice.person))
bob.disconnected_by(alice.person)
end
it 'removes notitications' do
alice.share_with(eve.person, alice.aspects.first)
Notifications::StartedSharing.where(:recipient_id => eve.id).first.should_not be_nil
eve.disconnected_by(alice.person)
Notifications::StartedSharing.where(:recipient_id => eve.id).first.should be_nil
end
end
describe '#disconnect' do
@ -58,7 +65,7 @@ describe Diaspora::UserModules::Connecting do
end
it 'should remove the contact from all aspects they are in' do
contact = alice.contact_for(bob.person)
contact = alice.contact_for(bob.person)
new_aspect = alice.aspects.create(:name => 'new')
alice.add_contact_to_aspect(contact, new_aspect)
@ -75,7 +82,7 @@ describe Diaspora::UserModules::Connecting do
alice.share_with(eve.person, alice.aspects.first)
}.should change(alice.contacts, :count).by(1)
end
it 'does not set mutual on intial share request' do
alice.share_with(eve.person, alice.aspects.first)
alice.contacts.find_by_person_id(eve.person.id).should_not be_mutual
@ -87,7 +94,7 @@ describe Diaspora::UserModules::Connecting do
alice.contacts.find_by_person_id(eve.person.id).should be_mutual
end
it 'adds a contact to an aspect' do
contact = alice.contacts.create(:person => eve.person)
alice.contacts.stub!(:find_or_initialize_by_person_id).and_return(contact)
@ -126,7 +133,7 @@ describe Diaspora::UserModules::Connecting do
alice.share_with(eve.person, a2)
end
end
it 'sets receiving' do
alice.share_with(eve.person, alice.aspects.first)
alice.contact_for(eve.person).should be_receiving