Clarify documentation on using initialize_with
Using ignore blocks to avoid duplicate assignment is obsolete since factory_girl 4.0. Closes #622
This commit is contained in:
parent
b97b36a42b
commit
493c9ad031
|
@ -873,20 +873,15 @@ end
|
|||
sequence(:email) { |n| "person#{n}@example.com" }
|
||||
|
||||
factory :user do
|
||||
ignore do
|
||||
name "Jane Doe"
|
||||
end
|
||||
|
||||
name "Jane Doe"
|
||||
email
|
||||
|
||||
initialize_with { new(name) }
|
||||
end
|
||||
|
||||
build(:user).name # Jane Doe
|
||||
```
|
||||
|
||||
Notice that I ignored the `name` attribute. If you don't want attributes
|
||||
reassigned after your object has been instantiated, you'll want to `ignore` them.
|
||||
|
||||
Although factory_girl is written to work with ActiveRecord out of the box, it
|
||||
can also work with any Ruby class. For maximum compatibiltiy with ActiveRecord,
|
||||
the default initializer builds all instances by calling `new` on your build class
|
||||
|
@ -908,9 +903,7 @@ For example:
|
|||
|
||||
```ruby
|
||||
factory :user do
|
||||
ignore do
|
||||
name "John Doe"
|
||||
end
|
||||
name "John Doe"
|
||||
|
||||
initialize_with { User.build_with_name(name) }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue