Closed ajays1991 closed 7 years ago
You are correct that the execution behavior is different. Fabrication is not creating everything using nested attributes as your code does through a controller. You have validations on the associations and the way you're invoking fabrication is causing objects to persist in an order your application code does not expect.
Your controller logic is likely doing a build
on each object while it creates the graph of objects to save then when you call save
on the parent it persists the group all at once. You should play around with using fabricate.build
on the child objects and I think you'll see better results.
Hi,
I observed a weird behaviour with fabrication.
Followings are my models
Model Fabricators
When i try to fabricate lead with followers, this fails
with the following error.
ActiveRecord::RecordInvalid: Validation failed: Followings is invalid
as it now getting the account_id from parent(inherits_from). I debug it and also found that followable_id is also nil. whereas the same is working fine through controllers and model create attributes.
This points me different execution behaviour for models through fabricator or normal.
Thanks