From f800d50a2b80809f4a3a21c5ba2f74554a2a9c4f Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Thu, 10 Nov 2011 16:14:37 -0800 Subject: [PATCH] i think this works --- app/controllers/users_controller.rb | 1 - app/models/account_deletion.rb | 7 +++++-- app/models/user.rb | 2 +- lib/postzord/receiver/public.rb | 2 ++ spec/models/account_deletion_spec.rb | 22 +++++++++++++++------- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 62c91f76b..4f47ee730 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -81,7 +81,6 @@ class UsersController < ApplicationController def destroy if params[:user] && params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password]) - Resque.enqueue(Jobs::DeleteAccount, current_user.id) current_user.close_account! sign_out current_user flash[:notice] = I18n.t 'users.destroy.success' diff --git a/app/models/account_deletion.rb b/app/models/account_deletion.rb index 77918103b..5e71fd0c1 100644 --- a/app/models/account_deletion.rb +++ b/app/models/account_deletion.rb @@ -14,7 +14,6 @@ class AccountDeletion < ActiveRecord::Base xml_attr :diaspora_handle - def person=(person) self[:diaspora_handle] = person.diaspora_handle self[:person_id] = person.id @@ -37,10 +36,14 @@ class AccountDeletion < ActiveRecord::Base end def subscribers(user) - person.owner.contact_people | Person.who_have_reshared_a_users_posts(person.owner) + person.owner.contact_people.remote | Person.who_have_reshared_a_users_posts(person.owner).remote end def dispatch Postzord::Dispatcher.build(person.owner, self).post end + + def public? + true + end end diff --git a/app/models/user.rb b/app/models/user.rb index 8a35d1cfa..61803e285 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -490,9 +490,9 @@ class User < ActiveRecord::Base end def close_account! - AccountDeletion.create(:person => self.person) self.person.lock_access! self.lock_access! + AccountDeletion.create(:person => self.person) end def clear_account! diff --git a/lib/postzord/receiver/public.rb b/lib/postzord/receiver/public.rb index 277de7bb1..cd93179a2 100644 --- a/lib/postzord/receiver/public.rb +++ b/lib/postzord/receiver/public.rb @@ -23,6 +23,8 @@ class Postzord::Receiver::Public < Postzord::Receiver if @object.respond_to?(:relayable?) receive_relayable + elsif @object.is_a?(AccountDeletion) + #nothing else Resque.enqueue(Jobs::ReceiveLocalBatch, @object.class.to_s, @object.id, self.recipient_user_ids) true diff --git a/spec/models/account_deletion_spec.rb b/spec/models/account_deletion_spec.rb index 50f02ec15..5bd96f79f 100644 --- a/spec/models/account_deletion_spec.rb +++ b/spec/models/account_deletion_spec.rb @@ -42,22 +42,30 @@ describe AccountDeletion do it "sends the account deletion xml" do @ad = AccountDeletion.new(:person => alice.person) @ad.send(:dispatch) + end + it 'creates a public postzord' do + Postzord::Dispatcher::Public.should_receive(:new).and_return(stub.as_null_object) + @ad = AccountDeletion.new(:person => alice.person) + @ad.send(:dispatch) end end describe "#subscribers" do - it 'includes all contacts' do + it 'includes all remote contacts' do @ad = AccountDeletion.new(:person => alice.person) - @ad.person.owner.should_receive(:contact_people).and_return([remote_raphael]) - @ad.subscribers(alice).should include(remote_raphael) + alice.share_with(remote_raphael, alice.aspects.first) + + @ad.subscribers(alice).should == [remote_raphael] end - it 'includes resharers' do + it 'includes remote resharers' do @ad = AccountDeletion.new(:person => alice.person) - p = Factory(:person) - Person.should_receive(:who_have_reshared_a_users_posts).with(alice).and_return([p]) - @ad.subscribers(alice).should include(p) + sm = Factory( :status_message, :public => true, :author => alice.person) + r1 = Factory( :reshare, :author => remote_raphael, :root => sm) + r2 = Factory( :reshare, :author => local_luke.person, :root => sm) + + @ad.subscribers(alice).should == [remote_raphael] end end