1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Add note about sequences and uniqueness [ci skip]

Closes #1393
This commit is contained in:
Daniel Colson 2020-06-22 13:32:20 -04:00 committed by GitHub
parent f223c7d763
commit 218eb72984
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,6 +52,7 @@ Getting Started
+ [Without a block](#without-a-block)
+ [Aliases](#aliases-1)
+ [Rewinding](#rewinding)
+ [Uniqueness](#uniqueness)
* [Traits](#traits)
+ [Defining traits](#defining-traits)
+ [As implicit attributes](#as-implicit-attributes-1)
@ -878,6 +879,22 @@ generate(:email) # "person1@example.com"
This rewinds all registered sequences.
### Uniqueness
When working with uniqueness constraints, be careful not to pass in override values that will conflict with the generated sequence values.
In this example the email will be the same for both users. If email must be unique, this code will error:
```rb
factory :user do
sequence(:email) { |n| "person#{n}@example.com" }
end
FactoryBot.create(:user, email: "person1@example.com")
FactoryBot.create(:user)
```
Traits
------