Model attribute methods are publicly callable

This commit is contained in:
Akira Matsuda 2020-10-02 13:48:33 +09:00
parent 674fd96d48
commit 5321f94066
2 changed files with 3 additions and 3 deletions

View File

@ -146,7 +146,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
ModelWithWeirdNamesAttributes.define_attribute_method(:'a?b')
assert_respond_to ModelWithWeirdNamesAttributes.new, :'a?b'
assert_equal "value of a?b", ModelWithWeirdNamesAttributes.new.send("a?b")
assert_equal "value of a?b", ModelWithWeirdNamesAttributes.new.public_send("a?b")
ensure
ModelWithWeirdNamesAttributes.undefine_attribute_methods
end
@ -182,7 +182,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
ModelWithAttributesWithSpaces.define_attribute_methods(:'foo bar')
assert_respond_to ModelWithAttributesWithSpaces.new, :'foo bar'
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar')
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.public_send(:'foo bar')
ensure
ModelWithAttributesWithSpaces.undefine_attribute_methods
end

View File

@ -139,7 +139,7 @@ class JsonSerializationTest < ActiveModel::TestCase
assert_kind_of Hash, json
assert_kind_of Hash, json["contact"]
%w(name age created_at awesome preferences).each do |field|
assert_equal @contact.send(field).as_json, json["contact"][field]
assert_equal @contact.public_send(field).as_json, json["contact"][field]
end
ensure
Contact.include_root_in_json = original_include_root_in_json