From 972c71d1e449851972a23746d45ed0bf319cec5a Mon Sep 17 00:00:00 2001 From: Jeff Cole Date: Sat, 19 Mar 2016 14:20:20 -0600 Subject: [PATCH] Add trait transient attributes to GETTING_STARTED It might not otherwise be clear to readers that this is possible, though it represents a worthwhile use case. --- GETTING_STARTED.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 91a74b5..77ec681 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -748,7 +748,7 @@ end create(:post).author ``` -Finally, traits can be used within other traits to mix in their attributes. +Traits can be used within other traits to mix in their attributes. ```ruby FactoryGirl.define do @@ -765,6 +765,24 @@ FactoryGirl.define do end ``` +Finally, traits can accept transient attributes. + +```ruby +factory :invoice do + trait :with_amount do + transient do + amount 1 + end + + after(:create) do |invoice, evaluator| + create :line_item, invoice: invoice, amount: evaluator.amount + end + end +end + +create :invoice, :with_amount, amount: 2 +``` + Callbacks ---------