diff --git a/app/models/user.rb b/app/models/user.rb index 056b8c13b..5470b6365 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -39,7 +39,7 @@ class User < ActiveRecord::Base has_many :services has_many :user_preferences - before_destroy :disconnect_everyone, :remove_person + before_destroy :disconnect_everyone, :remove_mentions, :remove_person before_save do person.save if person && person.changed? end @@ -313,4 +313,11 @@ class User < ActiveRecord::Base } self.aspects.delete_all end + + def remove_mentions + Mention.where( :person_id => self.person.id).each do |mentioned_person| + mentioned_person.delete + end + end + end diff --git a/features/closes_account.feature b/features/closes_account.feature index 69e919123..2b491be0e 100644 --- a/features/closes_account.feature +++ b/features/closes_account.feature @@ -7,13 +7,32 @@ Feature: Close Account Scenario: user closes account Given I am signed in When I click on my name in the header - And I follow "account settings" + And I follow "account settings" And I click ok in the confirm dialog to appear next And I follow "Close Account" Then I should be on the home page - + When I go to the new user session page And I try to sign in Then I should be on the new user session page When I wait for the ajax to finish Then I should see "Invalid email or password." + + Scenario: post display should not throw error when mention is removed for the user whose account is closed + Given a user named "Bob Jones" with email "bob@bob.bob" + And a user named "Alice Smith" with email "alice@alice.alice" + And a user with email "bob@bob.bob" is connected with "alice@alice.alice" + When I sign in as "alice@alice.alice" + And I am on the home page + And I expand the publisher + And I fill in "status_message_fake_message" with "Hi, @{Bob Jones; bob_jones@example.org} long time no see" + And I press "Share" + And I log out + Then I sign in as "bob@bob.bob" + When I click on my name in the header + And I follow "account settings" + And I click ok in the confirm dialog to appear next + And I follow "Close Account" + Then I sign in as "alice@alice.alice" + And I am on the home page + Then I should see "Hi, Bob Jones long time no see" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bce2ffc5c..fa05afd72 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -381,6 +381,11 @@ describe User do }.should change {alice.invitations_to_me(true).count }.by(-1) end + it 'should remove mentions' do + alice.should_receive(:remove_mentions) + alice.destroy + end + it 'should remove person' do alice.should_receive(:remove_person) alice.destroy @@ -421,6 +426,17 @@ describe User do end end + describe '#remove_mentions' do + it 'should remove the mentions' do + person = alice.person + sm = Factory(:status_message) + mention = Mention.create(:person => person, :post=> sm) + alice.reload + alice.destroy + proc { mention.reload }.should raise_error ActiveRecord::RecordNotFound + end + end + describe '#disconnect_everyone' do it 'has no error on a local friend who has deleted his account' do