From 218eb72984c7191247e770963afd2234f16b5780 Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Mon, 22 Jun 2020 13:32:20 -0400 Subject: [PATCH] Add note about sequences and uniqueness [ci skip] Closes #1393 --- GETTING_STARTED.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index daca3d5..ad089ee 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -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 ------