As per the shared code,
when you call FactoryGirl.create(:click)
,
it will go to execute factory :click
where it finds association :offer, factory: :offer
which in turn calls factory: :offer
where you create a country with name "United States"
and slug "us"
for the first time.
Again, in factory :click
, it finds association :user, factory: :user
which in turn calls factory: :user
where you create a country again with the same name "United States"
and slug "us"
for the second time.
Issue #1: Validation failed: Name has already been taken, Slug has already been taken
The above error is because of the uniqueness constraint on Country
model for name
and slug
.
Issue #2: Validation failed: Country can't be blank
When you do association :country, factory: :country, strategy: :build
then strategy: :build
only creates an instance of Country, it does create a record in database.
The Country can't be blank
error is because you didn't create a country record in the database for user
and offer
. And you must be having a validation presence: true
in these two models for country
OR schema level check of not null
.