DEV Community

Discussion on: FactoryBot .find_or_create_by

Collapse
 
edisonywh profile image
Edison Yap

Great article! Didn't know you could do this on FactoryBot. Is this similar to the FactoryBot's use_parent_strategy?

Collapse
 
jooeycheng profile image
Joey Cheng

use_parent_strategy is something different (more info on their docs), it tells FactoryBot whether or not to use the parent's strategy (eg: build or create).

For example, given a model User and Country (User belongs_to Country), when use_parent_strategy=true, calling build(:user) will also build (instead of create) the associated Country, because it follows the "parent strategy of build".

However, FactoryBot custom strategies is something different that I want to explore. Perhaps defining a new find_or_create strategy.