Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue81: set blocker_id correctly so that only the blocker is able to… #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/has_friendship/friendable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions lib/has_friendship/friendship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ 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
transition all - [:blocked] => :blocked
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,
Expand Down
2 changes: 1 addition & 1 deletion spec/has_friendship/friendable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down