Skip to content

Commit

Permalink
Merge pull request #76 from grosser/grosser/fix-respond-to
Browse files Browse the repository at this point in the history
fix respond_to blowing up because of extra include_all argument
  • Loading branch information
jamesarosen committed Jul 1, 2014
2 parents 6162065 + 5ab8534 commit f7800d0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
30 changes: 1 addition & 29 deletions lib/arturo.rb
Expand Up @@ -6,8 +6,7 @@ module Arturo
require 'arturo/feature_caching'
require 'arturo/engine' if defined?(Rails) && Rails::VERSION::MAJOR >= 3

class <<self

class << self
# Quick check for whether a feature is enabled for a recipient.
# @param [String, Symbol] feature_name
# @param [#id] recipient
Expand All @@ -16,32 +15,5 @@ def feature_enabled_for?(feature_name, recipient)
f = self::Feature.to_feature(feature_name)
f && f.enabled_for?(recipient)
end

ENABLED_FOR_METHOD_NAME = /^(\w+)_enabled_for\?$/

ENABLED_FOR_METHOD_NAME_WARNING = "Arturos FEATURE_enabled_for?(OBJECT) methods are going away, use feature_enabled_for?(FEATURE, OBJECT)"

def respond_to_missing?(symbol, include_all = false)
if symbol.to_s =~ ENABLED_FOR_METHOD_NAME
warn ENABLED_FOR_METHOD_NAME_WARNING
true
else
super
end
end

def respond_to?(symbol, include_all = false)
respond_to_missing? symbol, include_all
end

def method_missing(symbol, *args, &block)
if (args.length == 1 && match = ENABLED_FOR_METHOD_NAME.match(symbol.to_s))
warn ENABLED_FOR_METHOD_NAME_WARNING
feature_enabled_for?(match[1], args[0])
else
super(symbol, *args, &block)
end
end

end
end
6 changes: 0 additions & 6 deletions test/dummy_app/test/unit/feature_test.rb
Expand Up @@ -36,12 +36,6 @@ def test_feature_enabled_for_non_existent_feature
refute ::Arturo.feature_enabled_for?(:does_not_exist, 'Paula')
end

def test_x_enabled_for
@feature = create(:feature, :deployment_percentage => 100, :symbol => :foo)
recipient = stub('User', :to_s => 'Paula', :id => 12)
assert ::Arturo.foo_enabled_for?(recipient), "#{feature} should be enabled for #{recipient}"
end

def test_requires_a_symbol
feature.symbol = nil
refute feature.valid?
Expand Down

0 comments on commit f7800d0

Please sign in to comment.