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 | |
parent | 69742ca8fa05509f7d7c5512cb6d8e002ecb3ab3 (diff) | |
download | rails-c7c35be8fe30b3e29a5d05edae767f7d6a286911.tar.gz rails-c7c35be8fe30b3e29a5d05edae767f7d6a286911.tar.bz2 rails-c7c35be8fe30b3e29a5d05edae767f7d6a286911.zip |
AS::Concern includes InstanceMethods module if it exists
-rw-r--r-- | actionpack/lib/action_controller/base/chained/filters.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/concern.rb | 1 | ||||
-rw-r--r-- | activesupport/test/concern_test.rb | 17 |
4 files changed, 15 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/base/chained/filters.rb b/actionpack/lib/action_controller/base/chained/filters.rb index e121c0129d..f528dd0686 100644 --- a/actionpack/lib/action_controller/base/chained/filters.rb +++ b/actionpack/lib/action_controller/base/chained/filters.rb @@ -1,11 +1,6 @@ module ActionController #:nodoc: module Filters #:nodoc: - def self.included(base) - base.class_eval do - extend ClassMethods - include ActionController::Filters::InstanceMethods - end - end + extend ActiveSupport::Concern class FilterChain < ActiveSupport::Callbacks::CallbackChain #:nodoc: def append_filter_to_chain(filters, filter_type, &block) diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 04f4ed47ac..00557ec702 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -106,8 +106,6 @@ module ActiveRecord depends_on ActiveModel::Validations included do - include Validations::InstanceMethods - alias_method_chain :save, :validation alias_method_chain :save!, :validation 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 |