Skip to content

Commit

Permalink
Merge pull request rails#30836 from shioyama/generated_attribute_meth…
Browse files Browse the repository at this point in the history
…ods_include_mutex

Include Mutex_m into GeneratedAttributeMethods instead of extending instance
  • Loading branch information
matthewd committed Oct 9, 2017
2 parents 3564cd9 + fb800fe commit 1b36e2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions activerecord/lib/active_record/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def self.set_name_cache(name, value)

BLACKLISTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)

class GeneratedAttributeMethods < Module; end # :nodoc:
class GeneratedAttributeMethods < Module #:nodoc:
include Mutex_m
end

module ClassMethods
def inherited(child_class) #:nodoc:
Expand All @@ -42,7 +44,7 @@ def inherited(child_class) #:nodoc:
end

def initialize_generated_modules # :nodoc:
@generated_attribute_methods = GeneratedAttributeMethods.new { extend Mutex_m }
@generated_attribute_methods = GeneratedAttributeMethods.new
@attribute_methods_generated = false
include @generated_attribute_methods

Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,11 @@ def some_method_that_is_not_on_super
assert_equal ["title"], model.accessed_fields
end

test "generated attribute methods ancestors have correct class" do
mod = Topic.send(:generated_attribute_methods)
assert_match %r(GeneratedAttributeMethods), mod.inspect
end

private

def new_topic_like_ar_class(&block)
Expand Down

0 comments on commit 1b36e2c

Please sign in to comment.