stepford 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -16
- data/lib/stepford/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -159,9 +159,15 @@ To generate traits for each association that would be included with `--associati
|
|
159
159
|
|
160
160
|
##### Associations
|
161
161
|
|
162
|
-
|
162
|
+
If you use the (cache) wrapper to automatically generate factories, you may not need to generate associations. We had interdependence issues with factories. When there are NOT NULLs on foreign keys and/or presence validations, etc. you can't just use `after(:create)` or `after(:build)` to set associations, and without those you can have issues with "Trait not registered" or "Factory not registered" with interdependent factory associations.
|
163
163
|
|
164
|
-
However, if you don't have anything that complex or don't mind hand-editing the factories to try to fix issues,
|
164
|
+
However, if you don't have anything that complex or don't mind hand-editing the factories to try to fix issues, these might help.
|
165
|
+
|
166
|
+
###### Include Required Assocations
|
167
|
+
|
168
|
+
To include NOT NULL foreign key associations or presence validated associations:
|
169
|
+
|
170
|
+
bundle exec stepford factories --include-required-associations
|
165
171
|
|
166
172
|
###### Include All Associations
|
167
173
|
|
@@ -169,21 +175,15 @@ To include all associations even if they aren't deemed to be required by not nul
|
|
169
175
|
|
170
176
|
bundle exec stepford factories --associations
|
171
177
|
|
172
|
-
######
|
178
|
+
###### Checking Model Associations
|
173
179
|
|
174
180
|
If `--associations` or `--validate-associations` is specified, Stepford first loads Rails and attempts to check your models for broken associations.
|
175
181
|
|
176
182
|
If associations are deemed broken, it will output proposed changes.
|
177
183
|
|
178
|
-
######
|
179
|
-
|
180
|
-
With `--include-required-associations` it will include NOT NULL foreign key associations or presence validated associations.
|
184
|
+
###### Caching Associations
|
181
185
|
|
182
|
-
|
183
|
-
|
184
|
-
Use `--cache-associations` will use the .
|
185
|
-
|
186
|
-
This uses the [factory_girl-cache][factory_girl-cache] gem in the autogenerated factories, so you will need to include it also in your Gemfile:
|
186
|
+
Use `--cache-associations` will use the [factory_girl-cache][factory_girl-cache] gem in the autogenerated factories, so you will need to include it also in your Gemfile:
|
187
187
|
|
188
188
|
gem 'factory_girl-cache'
|
189
189
|
|
@@ -191,6 +191,8 @@ and
|
|
191
191
|
|
192
192
|
bundle install
|
193
193
|
|
194
|
+
See the Factory Girl Wrapper section for a possibly more useful way to use FactoryGirlCache.
|
195
|
+
|
194
196
|
##### No IDs
|
195
197
|
|
196
198
|
If working with a legacy schema, you may have models with foreign_key columns that you don't have associations defined for in the model. If that is the case, we don't want to assign arbitrary integers to them and try to create a record. If that is the case, try `--exclude-all-ids`, which will exclude those ids as attributes defined in the factories and you can add associations as needed to get things working.
|
@@ -211,7 +213,7 @@ See [Testing all Factories (with RSpec)][test_factories] in the FG wiki.
|
|
211
213
|
|
212
214
|
If you have duplicate factory definitions during Rails load, it may complain. Just move, rename, or remove the offending files and factories and retry.
|
213
215
|
|
214
|
-
|
216
|
+
The CLI produces factories that use Ruby 1.9 hash syntax. If you aren't using Ruby 1.9, it may not fail during generation, but it might later when loading the factories.
|
215
217
|
|
216
218
|
If you are using STI, you'll need to manually fix the value that goes into the `type` attribute, or you can remove those.
|
217
219
|
|
@@ -227,14 +229,12 @@ or maybe:
|
|
227
229
|
ActiveRecord::RecordInvalid:
|
228
230
|
Validation failed: Item The item is required., Pricer The pricer is required., Purchased by A purchaser is required.
|
229
231
|
|
230
|
-
you might
|
231
|
-
|
232
|
-
Without `--cache-associations`, you might get circular associations and could easily end up with:
|
232
|
+
or you might get:
|
233
233
|
|
234
234
|
SystemStackError:
|
235
235
|
stack level too deep
|
236
236
|
|
237
|
-
ThoughtBot's Josh Clayton
|
237
|
+
ThoughtBot's Josh Clayton provided some suggestions for this, including using methods to generate more complex object structures:
|
238
238
|
|
239
239
|
def post_containing_comment_by_author
|
240
240
|
author = FactoryGirl.create(:user)
|
@@ -264,6 +264,8 @@ or referring to created objects through associations, though he said multiple ne
|
|
264
264
|
comment = FactoryGirl.create(:comment, :authored_by_post_author)
|
265
265
|
comment.author == comment.post.author # true
|
266
266
|
|
267
|
+
This is the reason we wrote the Stepford Factory Girl Wrapper (see above). It automatically determines what needs to be set in what order and does create, create_list or build, build_list, etc. automatically.
|
268
|
+
|
267
269
|
### License
|
268
270
|
|
269
271
|
Copyright (c) 2012 Gary S. Weaver, released under the [MIT license][lic].
|
data/lib/stepford/version.rb
CHANGED