Reputation: 4964
create_list(:post, 3)
causes uniqueness validation to fail.
My factory that has a belongs_to association between Post and Author:
factory :post do
author
end
factory :author do
sequence(:internal_ref) { |n| n }
end
The Author
model has a uniqueness validation on internal_ref
.
UPDATE
After comments below that suggest cleaning the database, I have attempted to start from a brand new test database like this:
rake db:drop
rake db:create
rake db:schema:load
rake # to create test db and run the tests
And use the database_cleaner_gem
like this in spec_helper:
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
Upvotes: 1
Views: 252
Reputation: 4964
Closing this question. It looks like this suite was creating a list of author records in seeds.rb and was loading seeds.rb before running the test suite.
Upvotes: 1