diff --git a/acts_as_follower.gemspec b/acts_as_follower.gemspec index c05ac27..844e6ef 100644 --- a/acts_as_follower.gemspec +++ b/acts_as_follower.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_development_dependency "sqlite3" s.add_development_dependency "shoulda_create" - s.add_development_dependency "shoulda", "3.5.0" - s.add_development_dependency "factory_girl", "4.2.0" + s.add_development_dependency "shoulda", ">= 3.5.0" + s.add_development_dependency "factory_girl", ">= 4.2.0" s.add_development_dependency "rails", "~> 4.0.0" end diff --git a/lib/acts_as_follower/followable.rb b/lib/acts_as_follower/followable.rb index 4932b11..2c91272 100644 --- a/lib/acts_as_follower/followable.rb +++ b/lib/acts_as_follower/followable.rb @@ -55,6 +55,10 @@ def method_missing(m, *args) end end + def respond_to?(m, include_private = false) + super || m.to_s[/count_(.+)_followers/] || m.to_s[/(.+)_followers/] + end + def blocked_followers_count self.followings.blocked.count end diff --git a/lib/acts_as_follower/follower.rb b/lib/acts_as_follower/follower.rb index 17c86d8..a086ebe 100644 --- a/lib/acts_as_follower/follower.rb +++ b/lib/acts_as_follower/follower.rb @@ -97,6 +97,10 @@ def method_missing(m, *args) end end + def respond_to?(m, include_private = false) + super || m.to_s[/following_(.+)_count/] || m.to_s[/following_(.+)/] + end + # Returns a follow record for the current instance and followable object. def get_follow(followable) self.follows.unblocked.for_followable(followable).first diff --git a/test/acts_as_followable_test.rb b/test/acts_as_followable_test.rb index 74e2b8e..b7416a7 100644 --- a/test/acts_as_followable_test.rb +++ b/test/acts_as_followable_test.rb @@ -251,6 +251,18 @@ class ActsAsFollowableTest < ActiveSupport::TestCase assert_equal 1, @oasis.count_user_followers end end + + context "respond_to?" do + should "advertise that it responds to following methods" do + assert @oasis.respond_to?(:user_followers) + assert @oasis.respond_to?(:user_followers_count) + end + + should "return false when called with a nonexistent method" do + assert (not @oasis.respond_to?(:foobar)) + end + end + end end diff --git a/test/acts_as_follower_test.rb b/test/acts_as_follower_test.rb index d62ac3f..535195b 100644 --- a/test/acts_as_follower_test.rb +++ b/test/acts_as_follower_test.rb @@ -173,6 +173,17 @@ class ActsAsFollowerTest < ActiveSupport::TestCase end end + context "respond_to?" do + should "advertise that it responds to following methods" do + assert @sam.respond_to?(:following_users) + assert @sam.respond_to?(:following_users_count) + end + + should "return false when called with a nonexistent method" do + assert (not @sam.respond_to?(:foobar)) + end + end + context "destroying follower" do setup do @jon.destroy