mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #44322 from shioyama:fix_active_model_attribute_method_cache
Use different cache namespace for proxy calls
This commit is contained in:
commit
61cf029f82
3 changed files with 34 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
* Use different cache namespace for proxy calls
|
||||
|
||||
Models can currently have different attribute bodies for the same method
|
||||
names, leading to conflicts. Adding a new namespace `:active_model_proxy`
|
||||
fixes the issue.
|
||||
|
||||
*Chris Salzberg*
|
||||
|
||||
Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/activemodel/CHANGELOG.md) for previous changes.
|
||||
|
|
|
@ -319,7 +319,7 @@ module ActiveModel
|
|||
if respond_to?(generate_method, true)
|
||||
send(generate_method, attr_name.to_s, owner: owner)
|
||||
else
|
||||
define_proxy_call(owner, method_name, matcher.target, matcher.parameters, attr_name.to_s, namespace: :active_model)
|
||||
define_proxy_call(owner, method_name, matcher.target, matcher.parameters, attr_name.to_s, namespace: :active_model_proxy)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,33 @@ module ActiveModel
|
|||
attribute :string_field, default: "default string"
|
||||
end
|
||||
|
||||
class ModelWithGeneratedAttributeMethods
|
||||
include ActiveModel::Attributes
|
||||
|
||||
attribute :foo
|
||||
end
|
||||
|
||||
class ModelWithProxiedAttributeMethods
|
||||
include ActiveModel::AttributeMethods
|
||||
|
||||
attribute_method_suffix "="
|
||||
|
||||
define_attribute_method(:foo)
|
||||
|
||||
def attribute=(_, _)
|
||||
end
|
||||
end
|
||||
|
||||
test "models that proxy attributes do not conflict with models with generated methods" do
|
||||
ModelWithGeneratedAttributeMethods.new
|
||||
|
||||
model = ModelWithProxiedAttributeMethods.new
|
||||
|
||||
assert_nothing_raised do
|
||||
model.foo = "foo"
|
||||
end
|
||||
end
|
||||
|
||||
test "properties assignment" do
|
||||
data = ModelForAttributesTest.new(
|
||||
integer_field: "2.3",
|
||||
|
|
Loading…
Reference in a new issue