Open cesarjr opened 1 year ago
Unfortunately, giving a block to author
means it will be recognized as a dynamic attribute, not an association (internally therefore there will be no distinction between body
and author
, they are simply fields FactoryBot populates by running a block).
In addition, there is a deep rooted assumption in the code base that an association cannot be passed a block, it can only have traits and attribute overrides.
Maybe this post
factory could work for you?
factory :post do
body { "the post body" }
author
blog { association :blog, authors: [author] }
end
Do you think it'd make sense for factory_bot
to infer associations where possible?
Description
Hi team!
I noticed that FactoryBot is executing the associations block even when I'm using
attributes_for
.When I have one block which depends on another association, ruby is going to generate an
undefined method "the-association-name" for nil:NilClass
.I expected that the associations blocks weren't executed.
Thanks. You're great 💜!
Reproduction Steps
Expected behavior
I expected that the associations blocks weren't executed or the associations data were valids.
Actual behavior
The associations blocks are being executed with invalid data.