Skip to content

Commit

Permalink
Add restricted check
Browse files Browse the repository at this point in the history
  • Loading branch information
broskoski committed Apr 12, 2022
1 parent 9d47224 commit c44c9b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 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?(follower)
followings.blocked.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)
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_follower/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActsAsFollower
VERSION = '0.2.3'
VERSION = '0.2.4'
end
14 changes: 13 additions & 1 deletion test/acts_as_followable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
assert @sam.respond_to?(:followers)
assert @sam.respond_to?(:followed_by?)
assert @sam.respond_to?(:restricted_by?)
assert @sam.respond_to?(:restricted?)
end
end

Expand Down Expand Up @@ -79,7 +80,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end
end

context 'restricted_by' do
context 'restricted_by?' do
setup do
@jon.restrict(@sam)
end
Expand All @@ -90,6 +91,17 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end
end

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

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

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

0 comments on commit c44c9b3

Please sign in to comment.