Favor composition over inheritance for the JsonStrategy example

This commit is contained in:
Joshua Clayton 2012-04-24 10:20:37 -05:00
parent 95b88ac36f
commit 3a9900542b
1 changed files with 8 additions and 2 deletions

View File

@ -782,9 +782,15 @@ Inheritance can occasionally be useful; here's an example of inheriting from
`FactoryGirl::Strategy::Create` to build a JSON representation of your model.
```ruby
class JsonStrategy < FactoryGirl::Strategy::Create
class JsonStrategy
def initialize
@strategy = FactoryGirl.strategy_by_name(:create).new
end
delegate :association, to: :@strategy
def result(evaluation)
super.to_json
@strategy.result(evaluation).to_json
end
end
```