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.
This commit is contained in:
Jeff Cole 2016-03-19 14:20:20 -06:00 committed by Joshua Clayton
parent 330646ac15
commit 972c71d1e4
1 changed files with 19 additions and 1 deletions

View File

@ -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
---------