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])
|
block = current_user.blocks.new(params[:block])
|
||||||
|
|
||||||
if block.save
|
if block.save
|
||||||
|
disconnect_if_contact(block.person)
|
||||||
notice = {:notice => t('blocks.create.success')}
|
notice = {:notice => t('blocks.create.success')}
|
||||||
else
|
else
|
||||||
notice = {:error => t('blocks.create.failure')}
|
notice = {:error => t('blocks.create.failure')}
|
||||||
|
|
@ -20,4 +21,12 @@ class BlocksController < ApplicationController
|
||||||
end
|
end
|
||||||
redirect_to :back, notice
|
redirect_to :back, notice
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def disconnect_if_contact(person)
|
||||||
|
if contact = current_user.contact_for(person)
|
||||||
|
current_user.disconnect(contact, :force => true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnect(bad_contact)
|
def disconnect(bad_contact, opts={})
|
||||||
person = bad_contact.person
|
person = bad_contact.person
|
||||||
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
|
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
|
||||||
retraction = Retraction.for(self)
|
retraction = Retraction.for(self)
|
||||||
|
|
@ -64,7 +64,7 @@ module Diaspora
|
||||||
Postzord::Dispatcher.build(self, retraction).post
|
Postzord::Dispatcher.build(self, retraction).post
|
||||||
|
|
||||||
AspectMembership.where(:contact_id => bad_contact.id).delete_all
|
AspectMembership.where(:contact_id => bad_contact.id).delete_all
|
||||||
remove_contact(bad_contact)
|
remove_contact(bad_contact, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnected_by(person)
|
def disconnected_by(person)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ describe BlocksController do
|
||||||
describe "#create" do
|
describe "#create" do
|
||||||
it "creates a block" do
|
it "creates a block" do
|
||||||
expect {
|
expect {
|
||||||
post :create, :block => { :person_id => 2 }
|
post :create, :block => {:person_id => eve.person.id}
|
||||||
}.should change { alice.blocks.count }.by(1)
|
}.should change { alice.blocks.count }.by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -23,6 +23,11 @@ describe BlocksController do
|
||||||
|
|
||||||
flash.should_not be_empty
|
flash.should_not be_empty
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#destroy" do
|
describe "#destroy" do
|
||||||
|
|
@ -41,4 +46,22 @@ describe BlocksController do
|
||||||
}.should change { alice.blocks.count }.by(-1)
|
}.should change { alice.blocks.count }.by(-1)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue