642642
643643Or inline using attributes from the factory:
644644
645- ``` rb
645+ ``` ruby
646646factory :post do
647647 # ...
648648 author_last_name { " Writely" }
@@ -1153,7 +1153,7 @@ When working with uniqueness constraints, be careful not to pass in override val
11531153
11541154In this example the email will be the same for both users. If email must be unique, this code will error:
11551155
1156- ``` rb
1156+ ``` ruby
11571157factory :user do
11581158 sequence(:email ) { |n | " person#{ n } @example.com" }
11591159end
@@ -1419,7 +1419,7 @@ create :invoice, :with_amount, amount: 2
14191419
14201420Given an Active Record model with an enum attribute:
14211421
1422- ``` rb
1422+ ``` ruby
14231423class Task < ActiveRecord ::Base
14241424 enum status: {queued: 0 , started: 1 , finished: 2 }
14251425end
@@ -1429,7 +1429,7 @@ end
14291429factory\_ bot will automatically define traits for each possible value of the
14301430enum:
14311431
1432- ``` rb
1432+ ``` ruby
14331433FactoryBot .define do
14341434 factory :task
14351435end
@@ -1441,7 +1441,7 @@ FactoryBot.build(:task, :finished)
14411441
14421442Writing the traits out manually would be cumbersome, and is not necessary:
14431443
1444- ``` rb
1444+ ``` ruby
14451445FactoryBot .define do
14461446 factory :task do
14471447 trait :queued do
@@ -1466,7 +1466,7 @@ desired, it is possible to disable the feature by setting
14661466In that case, it is still possible to explicitly define traits for an enum
14671467attribute in a particular factory:
14681468
1469- ``` rb
1469+ ``` ruby
14701470FactoryBot .automatically_define_enum_traits = false
14711471
14721472FactoryBot .define do
@@ -1481,7 +1481,7 @@ specifically tied to Active Record enum attributes.
14811481
14821482With an array:
14831483
1484- ``` rb
1484+ ``` ruby
14851485class Task
14861486 attr_accessor :status
14871487end
@@ -1495,7 +1495,7 @@ end
14951495
14961496Or with a hash:
14971497
1498- ``` rb
1498+ ``` ruby
14991499class Task
15001500 attr_accessor :status
15011501end
0 commit comments