Permalink
Browse files

Favor composition over inheritance for the JsonStrategy example

  • Loading branch information...
1 parent 95b88ac commit 3a9900542b55aed51ebf4bae3c4f6d9a7795ef5a @joshuaclayton joshuaclayton committed Apr 24, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 GETTING_STARTED.md
View
10 GETTING_STARTED.md
@@ -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
```

2 comments on commit 3a99005

@WojtekKruszewski

Code comment still mentions inheritance.

@joshuaclayton
thoughtbot, inc. member

@wojt-eu Nice catch; fixed in bb00c91. Thanks!

Please sign in to comment.