From f42562f97bb791a7662fce0106a93eec211b2803 Mon Sep 17 00:00:00 2001 From: "Oriol Gual and Josep M. Bach" Date: Mon, 28 Feb 2011 14:31:29 +0100 Subject: Make ActiveSupport::Configurable work with modules [#6486 state:committed] Signed-off-by: Santiago Pastorino --- activesupport/lib/active_support/configurable.rb | 2 +- activesupport/test/configurable_test.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 644db0b205..be19189c04 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -26,7 +26,7 @@ module ActiveSupport module ClassMethods def config - @_config ||= if superclass.respond_to?(:config) + @_config ||= if respond_to?(:superclass) && superclass.respond_to?(:config) superclass.config.inheritable_copy else # create a new "anonymous" class that will host the compiled reader methods diff --git a/activesupport/test/configurable_test.rb b/activesupport/test/configurable_test.rb index 9c773c1944..2b28e61815 100644 --- a/activesupport/test/configurable_test.rb +++ b/activesupport/test/configurable_test.rb @@ -21,6 +21,12 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase assert_equal({ :foo => :bar }, Parent.config) end + test "adds a configuration hash to a module as well" do + mixin = Module.new { include ActiveSupport::Configurable } + mixin.config.foo = :bar + assert_equal({ :foo => :bar }, mixin.config) + end + test "configuration hash is inheritable" do assert_equal :bar, Child.config.foo assert_equal :bar, Parent.config.foo @@ -57,4 +63,4 @@ class ConfigurableActiveSupport < ActiveSupport::TestCase assert_respond_to child.config, :bar assert_respond_to child.new.config, :bar end -end \ No newline at end of file +end -- cgit v1.2.3