mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix configurable cristalization and tests.
This commit is contained in:
parent
c690b7124d
commit
d677097eb6
2 changed files with 18 additions and 8 deletions
|
@ -12,12 +12,12 @@ module ActiveSupport
|
|||
|
||||
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
|
||||
|
|
|
@ -58,16 +58,26 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue