diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-05-29 16:28:54 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-05-29 16:28:54 -0500 |
commit | c7c35be8fe30b3e29a5d05edae767f7d6a286911 (patch) | |
tree | c1f7aece2c62f276bebb4d9cf6365b5ae4bcb9a6 /activesupport | |
parent | 69742ca8fa05509f7d7c5512cb6d8e002ecb3ab3 (diff) | |
download | rails-c7c35be8fe30b3e29a5d05edae767f7d6a286911.tar.gz rails-c7c35be8fe30b3e29a5d05edae767f7d6a286911.tar.bz2 rails-c7c35be8fe30b3e29a5d05edae767f7d6a286911.zip |
AS::Concern includes InstanceMethods module if it exists
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/concern.rb | 1 | ||||
-rw-r--r-- | activesupport/test/concern_test.rb | 17 |
2 files changed, 14 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index 154f8807f7..a09a2420b3 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -7,6 +7,7 @@ module ActiveSupport def append_features(base) if super base.extend const_get("ClassMethods") if const_defined?("ClassMethods") + base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods") base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block") end end diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb index 22f7ec2064..40fcb7c57f 100644 --- a/activesupport/test/concern_test.rb +++ b/activesupport/test/concern_test.rb @@ -19,6 +19,9 @@ class ConcernTest < Test::Unit::TestCase end end + module InstanceMethods + end + included do self.included_ran = true end @@ -55,11 +58,11 @@ class ConcernTest < Test::Unit::TestCase def test_module_is_included_normally @klass.send(:include, Baz) assert_equal "baz", @klass.new.baz - assert_equal ConcernTest::Baz, @klass.included_modules[0] + assert @klass.included_modules.include?(ConcernTest::Baz) @klass.send(:include, Baz) assert_equal "baz", @klass.new.baz - assert_equal ConcernTest::Baz, @klass.included_modules[0] + assert @klass.included_modules.include?(ConcernTest::Baz) end def test_class_methods_are_extended @@ -68,6 +71,12 @@ class ConcernTest < Test::Unit::TestCase assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0] end + def test_instance_methods_are_included + @klass.send(:include, Baz) + assert_equal "baz", @klass.new.baz + assert @klass.included_modules.include?(ConcernTest::Baz::InstanceMethods) + end + def test_included_block_is_ran @klass.send(:include, Baz) assert_equal true, @klass.included_ran @@ -78,11 +87,11 @@ class ConcernTest < Test::Unit::TestCase assert_equal "bar", @klass.new.bar assert_equal "bar+baz", @klass.new.baz assert_equal "baz", @klass.baz - assert_equal [ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..1] + assert @klass.included_modules.include?(ConcernTest::Bar) end def test_depends_on_with_multiple_modules @klass.send(:include, Foo) - assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..2] + assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz::InstanceMethods, ConcernTest::Baz], @klass.included_modules[0..3] end end |