You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using this gem for a couple years, so I think I know my way around, but this one has got me stumped. I know I can reference other attributes when setting some attribute, but what about referencing the "current" value of the field itself?
With JSON fields becoming more prominent, I have found the need to merge some default hash with additional options more prominent. Consider:
create(:payload, :custom) or create(:payload, options: {default: "false"}), to get a "{default => "false"}" payload.
However, I can not do create(:payload, :custom, options: {additional: "yup"}) to get a {default: "false", additional: "yup"}} payload.
It would all be solved if I could access options to merge with the value e.g.:
FactoryBot.definedofactory:payloaddotransientdooptions{{}}enddata{{default: "true"}.merge(options)}trait:customdooptions{options.merge(default: "false")}# options can not reference itself :(endendend
Obviously, the example above causes an infinite loop and a stack error.
Is what I want possible? Maybe I am approaching this all wrong..
The text was updated successfully, but these errors were encountered:
It makes sense that options { options.merge(default: "false") } wouldn't work. Internally this defines an options method on an evaluator object. When we call that method, it executes the block in the context of the evaluator object (using instance_eval). So options { options } ends up being a recursive call to the same method.
Hi,
I've been using this gem for a couple years, so I think I know my way around, but this one has got me stumped. I know I can reference other attributes when setting some attribute, but what about referencing the "current" value of the field itself?
With JSON fields becoming more prominent, I have found the need to
merge
some default hash with additional options more prominent. Consider:Now I can do either:
create(:payload, :custom)
orcreate(:payload, options: {default: "false"})
, to get a "{default => "false"}" payload.However, I can not do
create(:payload, :custom, options: {additional: "yup"})
to get a {default: "false", additional: "yup"}} payload.It would all be solved if I could access
options
to merge with the value e.g.:Obviously, the example above causes an infinite loop and a stack error.
Is what I want possible? Maybe I am approaching this all wrong..
The text was updated successfully, but these errors were encountered: