mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Add documentation to using syntax methods inside dynamic attributes
Closes #355
This commit is contained in:
parent
29a5ab1a89
commit
3768d15322
1 changed files with 19 additions and 1 deletions
|
@ -130,6 +130,24 @@ factory :user do
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In addition to running other methods dynamically, you can use FactoryGirl's
|
||||||
|
syntax methods (like `build`, `create`, and `generate`) within dynamic
|
||||||
|
attributes without having to prefix the call with `FactoryGirl.`. This allows
|
||||||
|
you to do:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
sequence(:random_string) {|n| LoremIpsum.generate }
|
||||||
|
|
||||||
|
factory :post do
|
||||||
|
title { generate(:random_string) } # instead of FactoryGirl.generate(:random_string)
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :comment do
|
||||||
|
post
|
||||||
|
body { generate(:random_string) } # instead of FactoryGirl.generate(:random_string)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
Aliases
|
Aliases
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -372,7 +390,7 @@ Or in lazy attributes:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
factory :invite do
|
factory :invite do
|
||||||
invitee { FactoryGirl.generate(:email) }
|
invitee { generate(:email) }
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue