1
0
Fork 0
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:
Rafael Mendonça França 2015-06-12 13:23:15 -03:00
commit 8beb328bef
2 changed files with 26 additions and 1 deletions

View file

@ -132,7 +132,7 @@ module ActiveSupport
end
def class_methods(&class_methods_module_definition)
mod = const_defined?(:ClassMethods) ?
mod = const_defined?(:ClassMethods, false) ?
const_get(:ClassMethods) :
const_set(:ClassMethods, Module.new)

View file

@ -54,6 +54,11 @@ class ConcernTest < ActiveSupport::TestCase
include Bar, Baz
end
module Qux
module ClassMethods
end
end
def setup
@klass = Class.new
end
@ -70,6 +75,26 @@ class ConcernTest < ActiveSupport::TestCase
assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0]
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
@klass.include(Baz)
assert_equal true, @klass.included_ran