Skip to content
Browse files

AS::Concern includes InstanceMethods module if it exists

  • Loading branch information...
1 parent 69742ca commit c7c35be8fe30b3e29a5d05edae767f7d6a286911 @josh josh committed May 29, 2009
View
7 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)
View
2 activerecord/lib/active_record/validations.rb
@@ -106,8 +106,6 @@ module Validations
depends_on ActiveModel::Validations
included do
- include Validations::InstanceMethods
-
alias_method_chain :save, :validation
alias_method_chain :save!, :validation
View
1 activesupport/lib/active_support/concern.rb
@@ -7,6 +7,7 @@ module Concern
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
View
17 activesupport/test/concern_test.rb
@@ -19,6 +19,9 @@ def included_ran
end
end
+ module InstanceMethods
+ end
+
included do
self.included_ran = true
end
@@ -55,11 +58,11 @@ def setup
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 @@ def test_class_methods_are_extended
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 @@ def test_modules_dependencies_are_met
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

0 comments on commit c7c35be

Please sign in to comment.
Something went wrong with that request. Please try again.