diff --git a/lib/has_friendship/friendable.rb b/lib/has_friendship/friendable.rb index 10a1a19..13e1c24 100644 --- a/lib/has_friendship/friendable.rb +++ b/lib/has_friendship/friendable.rb @@ -77,7 +77,7 @@ def decline_request(friend) def block_friend(friend) on_relation_with(friend) do |one, other| - HasFriendship::Friendship.find_unblocked_friendship(one, other).block! + HasFriendship::Friendship.find_unblocked_friendship(one, other).block_by(self) end end diff --git a/lib/has_friendship/friendship.rb b/lib/has_friendship/friendship.rb index 6c2634a..a6f9611 100644 --- a/lib/has_friendship/friendship.rb +++ b/lib/has_friendship/friendship.rb @@ -20,10 +20,6 @@ class Friendship < ActiveRecord::Base end event :block do - before do - self.blocker_id = self.friendable.id - end - after do friendable.on_friendship_blocked(self) end @@ -31,6 +27,11 @@ class Friendship < ActiveRecord::Base end end + def block_by(blocker) + self.blocker_id = blocker.id + self.block! + end + def self.relation_attributes(one, other, status: nil) attr = { friendable_id: one.id, diff --git a/spec/has_friendship/friendable_spec.rb b/spec/has_friendship/friendable_spec.rb index 856dbbe..22ad654 100644 --- a/spec/has_friendship/friendable_spec.rb +++ b/spec/has_friendship/friendable_spec.rb @@ -291,7 +291,7 @@ friendship = find_friendship_record(user, friend) expect(friendship.friendable).to receive(:on_friendship_blocked) - friendship.block! + friendship.block_by(friend) end end end