diff --git a/app/models/aspect.rb b/app/models/aspect.rb index c3d9de4a1..97c812f81 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -8,7 +8,7 @@ class Aspect < ActiveRecord::Base has_many :aspect_memberships, :dependent => :destroy has_many :contacts, :through => :aspect_memberships - has_many :aspect_visibilities + has_many :aspect_visibilities, :dependent => :destroy has_many :posts, :through => :aspect_visibilities, :source => :shareable, :source_type => 'Post' has_many :photos, :through => :aspect_visibilities, :source => :shareable, :source_type => 'Photo' diff --git a/app/models/contact.rb b/app/models/contact.rb index f064ad929..1a428a898 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -11,7 +11,7 @@ class Contact < ActiveRecord::Base delegate :name, :diaspora_handle, :guid, :first_name, to: :person, prefix: true - has_many :aspect_memberships + has_many :aspect_memberships, :dependent => :destroy has_many :aspects, :through => :aspect_memberships has_many :share_visibilities, :source => :shareable, :source_type => 'Post' @@ -51,7 +51,7 @@ class Contact < ActiveRecord::Base Notification.where(:target_type => "Person", :target_id => person_id, :recipient_id => user_id, - :type => "Notifications::StartedSharing").delete_all + :type => "Notifications::StartedSharing").destroy_all end def dispatch_request diff --git a/app/models/mention.rb b/app/models/mention.rb index 58e6f4375..d03ef6483 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -22,6 +22,6 @@ class Mention < ActiveRecord::Base end def delete_notification - Notification.where(:target_type => self.class.name, :target_id => self.id).delete_all + Notification.where(:target_type => self.class.name, :target_id => self.id).destroy_all end end diff --git a/app/models/photo.rb b/app/models/photo.rb index 0e4b2bb82..60494cc06 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -51,7 +51,7 @@ class Photo < ActiveRecord::Base end def clear_empty_status_message - if self.status_message_guid && self.status_message.text_and_photos_blank? + if self.status_message && self.status_message.text_and_photos_blank? self.status_message.destroy else true diff --git a/lib/account_deleter.rb b/lib/account_deleter.rb index 314201f92..3d869ea8a 100644 --- a/lib/account_deleter.rb +++ b/lib/account_deleter.rb @@ -23,20 +23,22 @@ class AccountDeleter end def perform! - #person - delete_standard_person_associations - remove_conversation_visibilities - remove_share_visibilities_on_persons_posts - delete_contacts_of_me - tombstone_person_and_profile + ActiveRecord::Base.transaction do + #person + delete_standard_person_associations + remove_conversation_visibilities + remove_share_visibilities_on_persons_posts + delete_contacts_of_me + tombstone_person_and_profile - if self.user - #user deletion methods - remove_share_visibilities_on_contacts_posts - delete_standard_user_associations - disassociate_invitations - disconnect_contacts - tombstone_user + if self.user + #user deletion methods + remove_share_visibilities_on_contacts_posts + delete_standard_user_associations + disassociate_invitations + disconnect_contacts + tombstone_user + end end end @@ -55,13 +57,13 @@ class AccountDeleter def delete_standard_user_associations normal_ar_user_associates_to_delete.each do |asso| - self.user.send(asso).each{|model| model.delete} + self.user.send(asso).each{|model| model.destroy } end end def delete_standard_person_associations normal_ar_person_associates_to_delete.each do |asso| - self.person.send(asso).delete_all + self.person.send(asso).destroy_all end end diff --git a/lib/tasks/accounts.rake b/lib/tasks/accounts.rake index 1fcfbb553..91bfd7a02 100644 --- a/lib/tasks/accounts.rake +++ b/lib/tasks/accounts.rake @@ -7,9 +7,9 @@ namespace :accounts do account_delete.perform! end puts "OK." + else + puts "No acccount deletions to run." end - - puts "No acccount deletions to run." end end diff --git a/spec/lib/account_deleter_spec.rb b/spec/lib/account_deleter_spec.rb index 6554bbeec..339224c48 100644 --- a/spec/lib/account_deleter_spec.rb +++ b/spec/lib/account_deleter_spec.rb @@ -73,7 +73,7 @@ describe AccountDeleter do it 'removes all standard user associaltions' do @account_deletion.normal_ar_user_associates_to_delete.each do |asso| association_double = double - association_double.should_receive(:delete) + association_double.should_receive(:destroy) bob.should_receive(asso).and_return([association_double]) end @@ -88,7 +88,7 @@ describe AccountDeleter do it 'removes all standard person associaltions' do @account_deletion.normal_ar_person_associates_to_delete.each do |asso| association_double = double - association_double.should_receive(:delete_all) + association_double.should_receive(:destroy_all) bob.person.should_receive(asso).and_return(association_double) end