From 06110562ce16c8ee9628198f94248491f2b34431 Mon Sep 17 00:00:00 2001 From: Charles Broskoski Date: Tue, 5 Apr 2022 15:47:44 -0400 Subject: [PATCH] Add restricted_by? --- lib/acts_as_follower/followable.rb | 6 ++++++ test/acts_as_followable_test.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/acts_as_follower/followable.rb b/lib/acts_as_follower/followable.rb index 0773d92..fbd9e89 100644 --- a/lib/acts_as_follower/followable.rb +++ b/lib/acts_as_follower/followable.rb @@ -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 diff --git a/test/acts_as_followable_test.rb b/test/acts_as_followable_test.rb index 7586c6a..f7b4b6b 100644 --- a/test/acts_as_followable_test.rb +++ b/test/acts_as_followable_test.rb @@ -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 @@ -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