Skip to content

Commit

Permalink
Add restricted_by?
Browse files Browse the repository at this point in the history
  • Loading branch information
broskoski committed Apr 5, 2022
1 parent 9454f62 commit 0611056
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def followed_by?(follower)
followings.unblocked.for_follower(follower).first.present?
end

# Returns true if the current instance is blocked by the passed record
# Returns false if the current instance is not blocked by the passed record or no follow is found
def restricted_by?(follower)
followings.blocked.for_follower(follower).first.present?
end

def block(follower)
get_follow_for(follower) ? block_existing_follow(follower) : block_future_follow(follower)
end
Expand Down
12 changes: 12 additions & 0 deletions test/acts_as_followable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
assert @sam.respond_to?(:followers_count)
assert @sam.respond_to?(:followers)
assert @sam.respond_to?(:followed_by?)
assert @sam.respond_to?(:restricted_by?)
end
end

Expand Down Expand Up @@ -78,6 +79,17 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end
end

context 'restricted_by' do
setup do
@jon.restrict(@sam)
end

should 'return_restricted_status' do
assert_equal true, @jon.restricted_by?(@sam)
assert_equal false, @sam.restricted_by?(@jon)
end
end

context 'destroying a followable' do
setup do
@jon.destroy
Expand Down

0 comments on commit 0611056

Please sign in to comment.