Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respond_to? doesn't return true for dynamic methods added by method_missing #26

Merged
merged 2 commits into from
Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acts_as_follower.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/acts_as_follower/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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
11 changes: 11 additions & 0 deletions test/acts_as_follower_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down