diff --git a/app/models/person.rb b/app/models/person.rb index 50816bbeb..858827bfa 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -179,6 +179,8 @@ class Person private def remove_all_traces - Post.all(:person_id => id).each { |p| p.delete } + Post.where(:person_id => id).each { |p| p.delete } + Contact.where(:person_id => id).each { |c| c.delete } + Notification.where(:person_id => id).each { |n| n.delete } end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index a83e6b9a0..85dfa906c 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -100,24 +100,35 @@ describe Person do person_two.owns?(person_message).should be false end - it "deletes all of a person's posts upon person deletion" do - person = Factory.create(:person) + describe '#remove_all_traces' do + before do + @deleter = Factory(:person) + @status = Factory.create(:status_message, :person => @deleter) + @other_status = Factory.create(:status_message, :person => @person) + end - status = Factory.create(:status_message, :person => person) - Factory.create(:status_message, :person => @person) + it "deletes all notifications from a person's actions" do + note = Notification.create(:person_id => @deleter.id, :user_id => @user.id) + @deleter.destroy + Notification.where(:id => note.id).first.should be_nil + end - lambda {person.destroy}.should change(Post, :count).by(-1) - end + it "deletes all contacts pointing towards a person" do + @user.activate_contact(@deleter, @user.aspects.first) + @deleter.destroy + @user.contact_for(@deleter).should be_nil + end - it "does not delete a person's comments on person deletion" do - person = Factory.create(:person) + it "deletes all of a person's posts upon person deletion" do + lambda {@deleter.destroy}.should change(Post, :count).by(-1) + end - status_message = Factory.create(:status_message, :person => @person) + it "does not delete a person's comments on person deletion" do + Factory.create(:comment, :person_id => @deleter.id, :diaspora_handle => @deleter.diaspora_handle, :text => "i love you", :post => @other_status) + Factory.create(:comment, :person_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => @other_status) - Factory.create(:comment, :person_id => person.id, :diaspora_handle => person.diaspora_handle, :text => "i love you", :post => status_message) - Factory.create(:comment, :person_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => status_message) - - lambda {person.destroy}.should_not change(Comment, :count) + lambda {@deleter.destroy}.should_not change(Comment, :count) + end end describe "disconnecting" do