block user now removes a contact if user is blocking a contact
This commit is contained in:
parent
ee5bc25faf
commit
5df6bc1adf
3 changed files with 35 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ class BlocksController < ApplicationController
|
|||
block = current_user.blocks.new(params[:block])
|
||||
|
||||
if block.save
|
||||
disconnect_if_contact(block.person)
|
||||
notice = {:notice => t('blocks.create.success')}
|
||||
else
|
||||
notice = {:error => t('blocks.create.failure')}
|
||||
|
|
@ -20,4 +21,12 @@ class BlocksController < ApplicationController
|
|||
end
|
||||
redirect_to :back, notice
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def disconnect_if_contact(person)
|
||||
if contact = current_user.contact_for(person)
|
||||
current_user.disconnect(contact, :force => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ module Diaspora
|
|||
end
|
||||
end
|
||||
|
||||
def disconnect(bad_contact)
|
||||
def disconnect(bad_contact, opts={})
|
||||
person = bad_contact.person
|
||||
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
|
||||
retraction = Retraction.for(self)
|
||||
|
|
@ -64,7 +64,7 @@ module Diaspora
|
|||
Postzord::Dispatcher.build(self, retraction).post
|
||||
|
||||
AspectMembership.where(:contact_id => bad_contact.id).delete_all
|
||||
remove_contact(bad_contact)
|
||||
remove_contact(bad_contact, opts)
|
||||
end
|
||||
|
||||
def disconnected_by(person)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ describe BlocksController do
|
|||
describe "#create" do
|
||||
it "creates a block" do
|
||||
expect {
|
||||
post :create, :block => { :person_id => 2 }
|
||||
post :create, :block => {:person_id => eve.person.id}
|
||||
}.should change { alice.blocks.count }.by(1)
|
||||
end
|
||||
|
||||
|
|
@ -23,6 +23,11 @@ describe BlocksController do
|
|||
|
||||
flash.should_not be_empty
|
||||
end
|
||||
|
||||
it "calls #disconnect_if_contact" do
|
||||
@controller.should_receive(:disconnect_if_contact).with(bob.person)
|
||||
post :create, :block => {:person_id => bob.person.id}
|
||||
end
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
|
@ -41,4 +46,22 @@ describe BlocksController do
|
|||
}.should change { alice.blocks.count }.by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#disconnect_if_contact" do
|
||||
before do
|
||||
@controller.stub(:current_user).and_return(alice)
|
||||
end
|
||||
|
||||
it "calls disconnect with the force option if there is a contact for a given user" do
|
||||
contact = alice.contact_for(bob.person)
|
||||
alice.stub(:contact_for).and_return(contact)
|
||||
alice.should_receive(:disconnect).with(contact, hash_including(:force => true))
|
||||
@controller.send(:disconnect_if_contact, bob.person)
|
||||
end
|
||||
|
||||
it "doesn't call disconnect if there is a contact for a given user" do
|
||||
alice.should_not_receive(:disconnect)
|
||||
@controller.send(:disconnect_if_contact, eve.person)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue