added close account to user

This commit is contained in:
danielgrippi 2011-11-08 13:48:38 -08:00 committed by Maxwell Salzberg
parent cd6f97fa0e
commit e6ed2d397a
7 changed files with 89 additions and 14 deletions

View file

@ -33,6 +33,7 @@ class AccountDeletion
delete_photos
delete_posts
tombstone_person_and_profile
tombstone_user
end
#user deletions
@ -89,6 +90,10 @@ class AccountDeletion
self.person.close_account!
end
def tombstone_user
self.user.close_account!
end
def delete_contacts_of_me
Contact.all_contacts_of_person(self.person).destroy_all
end

View file

@ -91,7 +91,6 @@ class Person < ActiveRecord::Base
p
end
def self.search_query_string(query)
query = query.downcase
like_operator = postgres? ? "ILIKE" : "LIKE"
@ -276,8 +275,6 @@ class Person < ActiveRecord::Base
end
end
# @param person [Person]
# @param url [String]
def update_url(url)

View file

@ -148,7 +148,7 @@ class Profile < ActiveRecord::Base
def tombstone!
self.taggings.delete_all
clearable_profile_fields.each do |field|
clearable_fields.each do |field|
self[field] = nil
end
self.save
@ -174,7 +174,7 @@ class Profile < ActiveRecord::Base
end
private
def clearable_profile_fields
def clearable_fields
self.attributes.keys - Profile.protected_attributes.to_a - ["created_at", "updated_at", "person_id"]
end

View file

@ -488,4 +488,16 @@ class User < ActiveRecord::Base
errors[:base] << 'That username has already been taken'
end
end
def close_account!
clearable_fields.each do |field|
self[field] = nil
end
self.save
end
private
def clearable_fields
self.attributes.keys - ["username", "encrypted_password", "created_at", "updated_at"]
end
end

View file

@ -30,7 +30,8 @@ describe AccountDeletion do
:delete_posts,
:tombstone_person_and_profile,
:remove_share_visibilities,
:remove_conversation_visibilities].each do |method|
:remove_conversation_visibilities,
:tombstone_user].each do |method|
it "calls ##{method.to_s}" do
@account_deletion.should_receive(method)
@ -141,6 +142,13 @@ describe AccountDeletion do
end
end
describe "#tombstone_user" do
it 'calls strip_model on user' do
bob.should_receive(:close_account!)
@account_deletion.tombstone_user
end
end
it 'has all user association keys accounted for' do
all_keys = (@account_deletion.normal_ar_user_associates_to_delete + @account_deletion.special_ar_user_associations + @account_deletion.ignored_ar_user_associations)
all_keys.sort{|x, y| x.to_s <=> y.to_s}.should == User.reflections.keys.sort{|x, y| x.to_s <=> y.to_s}

View file

@ -264,7 +264,6 @@ describe Profile do
end
describe '#receive' do
it 'updates the profile in place' do
local_luke, local_leia, remote_raphael = set_up_friends
new_profile = Factory.build :profile
@ -281,7 +280,7 @@ describe Profile do
@profile = bob.person.profile
end
it "clears the profile fields" do
attributes = @profile.send(:clearable_profile_fields)
attributes = @profile.send(:clearable_fields)
@profile.tombstone!
@profile.reload
@ -296,10 +295,10 @@ describe Profile do
end
end
describe "#clearable_profile_fields" do
describe "#clearable_fields" do
it 'returns the current profile fields' do
profile = Factory.build :profile
profile.send(:clearable_profile_fields).sort.should ==
profile.send(:clearable_fields).sort.should ==
["diaspora_handle",
"first_name",
"last_name",

View file

@ -1003,6 +1003,60 @@ describe User do
user = Factory :user
Resque.should_receive(:enqueue).with(Jobs::ResetPassword, user.id)
user.send_reset_password_instructions
context "close account" do
before do
@user = bob
end
describe "#close_account!" do
it 'resets the password to a random string' do
random_pass = "12345678909876543210"
ActiveSupport::SecureRandom.should_receive(:hex).and_return(random_pass)
@user.close_account!
@user.valid_password?(random_pass)
end
it 'clears all the clearable fields' do
attributes = @user.send(:clearable_fields)
@user.close_account!
attributes.each do |attr|
@user.send(attr.to_sym).should be_blank
end
end
end
describe "#clearable_attributes" do
it 'has all the attributes' do
user = Factory.build :user
user.send(:clearable_fields).sort.should == %w{
serialized_private_key
getting_started
disable_mail
language
email
invitation_token
invitation_sent_at
reset_password_token
remember_token
remember_created_at
sign_in_count
current_sign_in_at
last_sign_in_at
current_sign_in_ip
last_sign_in_ip
invitation_service
invitation_identifier
invitation_limit
invited_by_id
invited_by_type
authentication_token
unconfirmed_email
confirm_email_token
locked_at
show_community_spotlight_in_stream
}.sort
end
end
end