From f705c39fa47d87bd1ea559ff3bbd7ddd4e3a861f Mon Sep 17 00:00:00 2001 From: Gareth Adams <> Date: Tue, 9 Jan 2024 15:34:26 +0000 Subject: [PATCH] Remove redundant `parent` method from RESTRICTED_CLASS_METHODS Previously, `parent` was added as one of the RESTRICTED_CLASS_METHODS as part of a commit (94b7328b08) in 2014 that stopped Rails `enum`s from being able to redefine important class methods. At the time, Rails monkey-patched `Module` with a `parent` class method that returned a module's containing module if it was nested. However, in October 2020 (167b4153ca) in Rails 6.1, this method was deprecated in favour of a renamed method `module_parent`. As such, the `parent` method doesn't need to be a restricted class method any more. --- activerecord/lib/active_record/attribute_methods.rb | 2 +- activerecord/test/cases/enum_test.rb | 2 +- activerecord/test/cases/scoping/named_scoping_test.rb | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 5440ab54a3a..88fd6cd3625 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -20,7 +20,7 @@ module ActiveRecord include Serialization end - RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass) + RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name superclass) class GeneratedAttributeMethods < Module # :nodoc: LOCK = Monitor.new diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 950f8005893..4865197bca5 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -535,7 +535,7 @@ class EnumTest < ActiveRecord::TestCase :save, # generates #save!, which conflicts with an AR method :proposed, # same value as an existing enum :public, :private, :protected, # some important methods on Module and Class - :name, :parent, :superclass, + :name, :superclass, :id # conflicts with AR querying ] diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index df92453fe26..52c8a8ba991 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -363,7 +363,6 @@ class NamedScopingTest < ActiveRecord::TestCase :protected, :private, :name, - :parent, :superclass ]