From 3768d153225b51a2158cefa5f9829fe39a130de1 Mon Sep 17 00:00:00 2001 From: Ben Zhang and Josh Clayton Date: Fri, 20 Apr 2012 16:15:09 -0400 Subject: [PATCH] Add documentation to using syntax methods inside dynamic attributes Closes #355 --- GETTING_STARTED.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 8e2546e..d2924c4 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -130,6 +130,24 @@ factory :user do 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 ------- @@ -372,7 +390,7 @@ Or in lazy attributes: ```ruby factory :invite do - invitee { FactoryGirl.generate(:email) } + invitee { generate(:email) } end ```