Permalink
Browse files

Fix configurable cristalization and tests.

  • Loading branch information...
1 parent fe6e890 commit c093ea9f4edb9ef3973afc76f062cda357054f01 @josevalim josevalim committed Jun 29, 2011
Showing with 18 additions and 8 deletions.
  1. +2 −2 activesupport/lib/active_support/configurable.rb
  2. +16 −6 activesupport/test/configurable_test.rb
View
4 activesupport/lib/active_support/configurable.rb
@@ -12,12 +12,12 @@ module Configurable
class Configuration < ActiveSupport::InheritableOptions
def compile_methods!
- self.class.compile_methods!(keys.reject {|key| respond_to?(key)})
+ self.class.compile_methods!(keys)
end
# compiles reader methods so we don't have to go through method_missing
def self.compile_methods!(keys)
- keys.each do |key|
+ keys.reject { |m| method_defined?(m) }.each do |key|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{key}; _get(#{key.inspect}); end
RUBY
View
22 activesupport/test/configurable_test.rb
@@ -58,16 +58,26 @@ class Child < Parent
child = Class.new(parent)
parent.config.bar = :foo
- assert !parent.config.respond_to?(:bar)
- assert !child.config.respond_to?(:bar)
- assert !child.new.config.respond_to?(:bar)
+ assert_method_not_defined parent.config, :bar
+ assert_method_not_defined child.config, :bar
+ assert_method_not_defined child.new.config, :bar
parent.config.compile_methods!
assert_equal :foo, parent.config.bar
assert_equal :foo, child.new.config.bar
- assert_respond_to parent.config, :bar
- assert_respond_to child.config, :bar
- assert_respond_to child.new.config, :bar
+ assert_method_defined parent.config, :bar
+ assert_method_defined child.config, :bar
+ assert_method_defined child.new.config, :bar
+ end
+
+ def assert_method_defined(object, method)
+ methods = object.public_methods.map(&:to_s)
+ assert methods.include?(method.to_s), "Expected #{methods.inspect} to include #{method.to_s.inspect}"
+ end
+
+ def assert_method_not_defined(object, method)
+ methods = object.public_methods.map(&:to_s)
+ assert !methods.include?(method.to_s), "Expected #{methods.inspect} to not include #{method.to_s.inspect}"
end
end

0 comments on commit c093ea9

Please sign in to comment.