1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #35595 from shioyama/generated_attribute_methods_namespaced_constant

Give GeneratedAttributeMethods module a name
This commit is contained in:
Rafael França 2019-03-19 21:17:02 -04:00 committed by GitHub
commit 3dee96e92b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -24,7 +24,7 @@ module ActiveRecord
RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass) RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)
class GeneratedAttributeMethods < Module #:nodoc: class GeneratedAttributeMethodsBuilder < Module #:nodoc:
include Mutex_m include Mutex_m
end end
@ -35,7 +35,8 @@ module ActiveRecord
end end
def initialize_generated_modules # :nodoc: def initialize_generated_modules # :nodoc:
@generated_attribute_methods = GeneratedAttributeMethods.new @generated_attribute_methods = const_set(:GeneratedAttributeMethods, GeneratedAttributeMethodsBuilder.new)
private_constant :GeneratedAttributeMethods
@attribute_methods_generated = false @attribute_methods_generated = false
include @generated_attribute_methods include @generated_attribute_methods
@ -88,7 +89,7 @@ module ActiveRecord
# If ThisClass < ... < SomeSuperClass < ... < Base and SomeSuperClass # If ThisClass < ... < SomeSuperClass < ... < Base and SomeSuperClass
# defines its own attribute method, then we don't want to overwrite that. # defines its own attribute method, then we don't want to overwrite that.
defined = method_defined_within?(method_name, superclass, Base) && defined = method_defined_within?(method_name, superclass, Base) &&
! superclass.instance_method(method_name).owner.is_a?(GeneratedAttributeMethods) ! superclass.instance_method(method_name).owner.is_a?(GeneratedAttributeMethodsBuilder)
defined || super defined || super
end end
end end

View file

@ -1083,7 +1083,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
test "generated attribute methods ancestors have correct class" do test "generated attribute methods ancestors have correct class" do
mod = Topic.send(:generated_attribute_methods) mod = Topic.send(:generated_attribute_methods)
assert_match %r(GeneratedAttributeMethods), mod.inspect assert_match %r(Topic::GeneratedAttributeMethods), mod.inspect
end end
private private