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
Maybe there is a bug on using FactoryGirl (or, at least, a "not common" way to handle object creation processes) with an after_update Ruby on Rails callback method as I explained here.
As you said in the Official Documentation, I tried to build my model from the rails console and I had not problem. I have trouble only when I use FactoryGirl as explained in the linked explanation.
The text was updated successfully, but these errors were encountered:
In the post, you mentioned running the non-FactoryGirl version of the code and had no errors, but I want to confirm.
Without seeing your factories, the code above would essentially run:
account=Account.newaccount.save!# Since this is Ruby, it'll evaluate this line as part of the hash first, before creating the useruser=User.newuser.account=accountuser.save!# The hash has been evaluated and we're assigning the account created from the hash
Now, the problem I see here is that the account requires a profile, which the user creates... but only after the account tries to call save!.
It looks like all of these models are pretty tightly coupled, so it may get a bit tricky. Without seeing your factories or rest of the models, my guess is you'd want a factory like this:
With all these interwoven models, again, it may be tricky figuring out how to set up your factories. In your case, since these records are all intertwined, you may want to look at delegation to move naming logic onto one of the models instead of having it spread across all three.
Good luck, and please post what you find here in case anyone else runs into the same issues.
Maybe there is a bug on using FactoryGirl (or, at least, a "not common" way to handle object creation processes) with an
after_update
Ruby on Rails callback method as I explained here.As you said in the Official Documentation, I tried to build my model from the rails console and I had not problem. I have trouble only when I use FactoryGirl as explained in the linked explanation.
The text was updated successfully, but these errors were encountered: