From e1508556912daafee0f318fe817fac5560d86ad2 Mon Sep 17 00:00:00 2001 From: "Peter M. Goldstein" Date: Tue, 21 Aug 2012 19:39:29 -0700 Subject: [PATCH 1/2] Update respond_to? so that it recognizes the dynamic methods added by this gem. --- lib/acts_as_follower/followable.rb | 4 ++++ lib/acts_as_follower/follower.rb | 4 ++++ test/acts_as_followable_test.rb | 12 ++++++++++++ test/acts_as_follower_test.rb | 11 +++++++++++ 4 files changed, 31 insertions(+) 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 From 85a61ff6083f6ce04fb9fb3d6cd97b83e7983e5b Mon Sep 17 00:00:00 2001 From: "Peter M. Goldstein" Date: Tue, 21 Aug 2012 19:39:51 -0700 Subject: [PATCH 2/2] Update gemspec so that the tests pass --- acts_as_follower.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acts_as_follower.gemspec b/acts_as_follower.gemspec index 642d7fc..a945ffd 100644 --- a/acts_as_follower.gemspec +++ b/acts_as_follower.gemspec @@ -20,7 +20,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