mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
parent
f223c7d763
commit
218eb72984
1 changed files with 17 additions and 0 deletions
|
@ -52,6 +52,7 @@ Getting Started
|
||||||
+ [Without a block](#without-a-block)
|
+ [Without a block](#without-a-block)
|
||||||
+ [Aliases](#aliases-1)
|
+ [Aliases](#aliases-1)
|
||||||
+ [Rewinding](#rewinding)
|
+ [Rewinding](#rewinding)
|
||||||
|
+ [Uniqueness](#uniqueness)
|
||||||
* [Traits](#traits)
|
* [Traits](#traits)
|
||||||
+ [Defining traits](#defining-traits)
|
+ [Defining traits](#defining-traits)
|
||||||
+ [As implicit attributes](#as-implicit-attributes-1)
|
+ [As implicit attributes](#as-implicit-attributes-1)
|
||||||
|
@ -878,6 +879,22 @@ generate(:email) # "person1@example.com"
|
||||||
|
|
||||||
This rewinds all registered sequences.
|
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
|
Traits
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue