mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20494 from knovoselic/active_support_concern_class_methods_fix
[ActiveSupport] Fix for #20489 - ActiveSupport::Concern#class_methods affects parent classes
This commit is contained in:
commit
8beb328bef
2 changed files with 26 additions and 1 deletions
|
@ -132,7 +132,7 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_methods(&class_methods_module_definition)
|
def class_methods(&class_methods_module_definition)
|
||||||
mod = const_defined?(:ClassMethods) ?
|
mod = const_defined?(:ClassMethods, false) ?
|
||||||
const_get(:ClassMethods) :
|
const_get(:ClassMethods) :
|
||||||
const_set(:ClassMethods, Module.new)
|
const_set(:ClassMethods, Module.new)
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,11 @@ class ConcernTest < ActiveSupport::TestCase
|
||||||
include Bar, Baz
|
include Bar, Baz
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Qux
|
||||||
|
module ClassMethods
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@klass = Class.new
|
@klass = Class.new
|
||||||
end
|
end
|
||||||
|
@ -70,6 +75,26 @@ class ConcernTest < ActiveSupport::TestCase
|
||||||
assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0]
|
assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_class_methods_are_extended_only_on_expected_objects
|
||||||
|
::Object.__send__(:include, Qux)
|
||||||
|
Object.extend(Qux::ClassMethods)
|
||||||
|
# module needs to be created after Qux is included in Object or bug won't
|
||||||
|
# be triggered
|
||||||
|
test_module = Module.new do
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def test
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@klass.include test_module
|
||||||
|
assert_equal false, Object.respond_to?(:test)
|
||||||
|
Qux.class_eval do
|
||||||
|
remove_const :ClassMethods
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_included_block_is_ran
|
def test_included_block_is_ran
|
||||||
@klass.include(Baz)
|
@klass.include(Baz)
|
||||||
assert_equal true, @klass.included_ran
|
assert_equal true, @klass.included_ran
|
||||||
|
|
Loading…
Reference in a new issue