diff --git a/app/models/account_deletion.rb b/app/models/account_deletion.rb index 11a1bfcb3a49ddfe7af39b5048bfd7ed506700e7..b929279bba8a73a6f723824ce14ccfac948c8a0b 100644 --- a/app/models/account_deletion.rb +++ b/app/models/account_deletion.rb @@ -18,7 +18,7 @@ class AccountDeletion < ApplicationRecord def perform! Diaspora::Federation::Dispatcher.build(person.owner, self).dispatch if person.local? - AccountDeleter.new(diaspora_handle).perform! + AccountDeleter.new(person).perform! end def subscribers diff --git a/lib/account_deleter.rb b/lib/account_deleter.rb index 0b917c4022f92c96f9c7388ed83483cc3dd9b4c4..8172510a0d37b4a07cfabf400030f00fcc497797 100644 --- a/lib/account_deleter.rb +++ b/lib/account_deleter.rb @@ -17,9 +17,9 @@ class AccountDeleter attr_accessor :person, :user - def initialize(diaspora_handle) - self.person = Person.where(:diaspora_handle => diaspora_handle).first - self.user = self.person.owner + def initialize(person) + self.person = person + self.user = person.owner end def perform! @@ -34,7 +34,6 @@ class AccountDeleter #user deletion methods remove_share_visibilities_on_contacts_posts delete_standard_user_associations - disconnect_contacts tombstone_user end @@ -44,17 +43,17 @@ class AccountDeleter #user deletions def normal_ar_user_associates_to_delete - %i(tag_followings services aspects user_preferences - notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers) + %i[tag_followings services aspects user_preferences + notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers] end def special_ar_user_associations - %i(person profile contacts auto_follow_back_aspect) + %i[person profile contacts auto_follow_back_aspect] end def ignored_ar_user_associations - %i(followed_tags invited_by contact_people aspect_memberships - ignored_people share_visibilities conversation_visibilities conversations reports) + %i[followed_tags invited_by contact_people aspect_memberships + ignored_people share_visibilities conversation_visibilities conversations reports] end def delete_standard_user_associations @@ -69,10 +68,6 @@ class AccountDeleter end end - def disconnect_contacts - user.contacts.destroy_all - end - # Currently this would get deleted due to the db foreign key constrainsts, # but we'll keep this method here for completeness def remove_share_visibilities_on_contacts_posts @@ -97,7 +92,7 @@ class AccountDeleter end def normal_ar_person_associates_to_delete - %i(posts photos mentions participations roles) + %i[posts photos mentions participations roles] end def ignored_or_special_ar_person_associations diff --git a/spec/integration/account_deletion_spec.rb b/spec/integration/account_deletion_spec.rb index 7c9346204439bfce47fcbe68aac3bc014e54ed4c..e9938c50c73d5d6e28e1fc795701671acb051522 100644 --- a/spec/integration/account_deletion_spec.rb +++ b/spec/integration/account_deletion_spec.rb @@ -1,11 +1,12 @@ describe "deleteing account", type: :request do def account_removal_method - AccountDeleter.new(subject.diaspora_handle).perform! + AccountDeleter.new(person).perform! subject.reload end context "of local user" do subject(:user) { FactoryGirl.create(:user_with_aspect) } + let(:person) { user.person } before do DataGenerator.create(subject, :generic_user_data) @@ -29,9 +30,7 @@ describe "deleteing account", type: :request do }.to(eq([true] * user.send(:clearable_fields).count))) end - it_behaves_like "it removes the person associations" do - subject(:person) { user.person } - end + it_behaves_like "it removes the person associations" end context "of remote person" do diff --git a/spec/lib/account_deleter_spec.rb b/spec/lib/account_deleter_spec.rb index e679201579f5285a749717a8f86cfd4290925f36..46d431d72ca30457ffc5f94157520ce2c0925c45 100644 --- a/spec/lib/account_deleter_spec.rb +++ b/spec/lib/account_deleter_spec.rb @@ -4,28 +4,28 @@ describe AccountDeleter do before do - @account_deletion = AccountDeleter.new(bob.person.diaspora_handle) + @account_deletion = AccountDeleter.new(bob.person) @account_deletion.user = bob end it "attaches the user" do - expect(AccountDeleter.new(bob.person.diaspora_handle).user).to eq(bob) - expect(AccountDeleter.new(remote_raphael.diaspora_handle).user).to eq(nil) + expect(AccountDeleter.new(bob.person).user).to eq(bob) + expect(AccountDeleter.new(remote_raphael).user).to eq(nil) end describe '#perform' do - user_removal_methods = %i( + user_removal_methods = %i[ delete_standard_user_associations remove_share_visibilities_on_contacts_posts - disconnect_contacts tombstone_user - ) + tombstone_user + ] - person_removal_methods = %i( + person_removal_methods = %i[ delete_contacts_of_me delete_standard_person_associations tombstone_person_and_profile remove_conversation_visibilities - ) + ] context "user deletion" do after do @@ -42,7 +42,7 @@ describe AccountDeleter do context "profile deletion" do before do - @profile_deletion = AccountDeleter.new(remote_raphael.diaspora_handle) + @profile_deletion = AccountDeleter.new(remote_raphael) @profile = remote_raphael.profile end @@ -57,7 +57,7 @@ describe AccountDeleter do context "person deletion" do before do - @person_deletion = AccountDeleter.new(remote_raphael.diaspora_handle) + @person_deletion = AccountDeleter.new(remote_raphael) end after do @@ -109,13 +109,6 @@ describe AccountDeleter do end context 'person associations' do - describe '#disconnect_contacts' do - it "deletes all of user's contacts" do - expect(bob.contacts).to receive(:destroy_all) - @account_deletion.disconnect_contacts - end - end - describe '#delete_contacts_of_me' do it 'deletes all the local contact objects where deleted account is the person' do contacts = double diff --git a/spec/models/account_deletion_spec.rb b/spec/models/account_deletion_spec.rb index 97243581856d5faad09be4749aba086f72c2b98e..7fc069984583fa07471460e12ae593345e029ce9 100644 --- a/spec/models/account_deletion_spec.rb +++ b/spec/models/account_deletion_spec.rb @@ -16,7 +16,7 @@ describe AccountDeletion, type: :model do describe "#perform!" do it "creates a deleter" do - expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(perform!: true)) + expect(AccountDeleter).to receive(:new).with(alice.person).and_return(double(perform!: true)) account_deletion.perform! end