Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend dangerous attribute methods with dangerous methods from Object #45883

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion activerecord/lib/active_record/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def dangerous_attribute_methods # :nodoc:
Base.instance_methods +
Base.private_instance_methods -
Base.superclass.instance_methods -
Base.superclass.private_instance_methods
Base.superclass.private_instance_methods +
%i[__id__ dup freeze hash object_id class clone]
).map { |m| -m.to_s }.to_set.freeze
end
end
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ def topic.approved; false; end
assert_predicate topic, :is_test?
end

test "raises ActiveRecord::DangerousAttributeError when defining an AR method in a model" do
%w(save create_or_update).each do |method|
test "raises ActiveRecord::DangerousAttributeError when defining an AR method or dangerous Object method in a model" do
%w(save create_or_update hash dup).each do |method|
klass = Class.new(ActiveRecord::Base)
klass.class_eval "def #{method}() 'defined #{method}' end"
assert_raise ActiveRecord::DangerousAttributeError do
Expand Down