Permalink
Browse files

version 0.8.1. updated doc

  • Loading branch information...
1 parent b183c53 commit 1d6dcbc1041a99a6a5a2299c9f9df2a0e8ae0060 @garysweaver committed Nov 7, 2012
Showing with 19 additions and 17 deletions.
  1. +18 −16 README.md
  2. +1 −1 lib/stepford/version.rb
View
@@ -159,38 +159,40 @@ To generate traits for each association that would be included with `--associati
##### Associations
-Associations in FactoryGirl aren't that great. There are factory interdependence issues (one factory requires another that requires it, etc.- that doesn't work that well) when you don't use `after(:create)` or `after(:build)`, and those don't work if you presence validate the associations or their foreign_keys have NOT NULL.
+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.
-However, if you don't have anything that complex or don't mind hand-editing the factories to try to fix issues, go for it. Here are the related methods.
+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.
+
+###### Include Required Assocations
+
+To include NOT NULL foreign key associations or presence validated associations:
+
+ bundle exec stepford factories --include-required-associations
###### Include All Associations
To include all associations even if they aren't deemed to be required by not null ActiveRecord constraints defined in the model:
bundle exec stepford factories --associations
-###### Stepford Checks Model Associations
+###### Checking Model Associations
If `--associations` or `--validate-associations` is specified, Stepford first loads Rails and attempts to check your models for broken associations.
If associations are deemed broken, it will output proposed changes.
-###### Include Required Assocations
-
-With `--include-required-associations` it will include NOT NULL foreign key associations or presence validated associations.
+###### Caching Associations
-###### Cache Associations
-
-Use `--cache-associations` will use the .
-
-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:
+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:
gem 'factory_girl-cache'
and
bundle install
+See the Factory Girl Wrapper section for a possibly more useful way to use FactoryGirlCache.
+
##### No IDs
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.
If you have duplicate factory definitions during Rails load, it may complain. Just move, rename, or remove the offending files and factories and retry.
-Stepford 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.
+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.
If you are using STI, you'll need to manually fix the value that goes into the `type` attribute, or you can remove those.
@@ -227,14 +229,12 @@ or maybe:
ActiveRecord::RecordInvalid:
Validation failed: Item The item is required., Pricer The pricer is required., Purchased by A purchaser is required.
-you might either need to modify those factories to set associations that are required or specify `--associations` in Stepford to attempt generate them.
-
-Without `--cache-associations`, you might get circular associations and could easily end up with:
+or you might get:
SystemStackError:
stack level too deep
-ThoughtBot's Josh Clayton also provided some suggestions for this, including using methods to generate more complex object structures:
+ThoughtBot's Josh Clayton provided some suggestions for this, including using methods to generate more complex object structures:
def post_containing_comment_by_author
author = FactoryGirl.create(:user)
@@ -264,6 +264,8 @@ or referring to created objects through associations, though he said multiple ne
comment = FactoryGirl.create(:comment, :authored_by_post_author)
comment.author == comment.post.author # true
+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.
+
### License
Copyright (c) 2012 Gary S. Weaver, released under the [MIT license][lic].
View
@@ -1,3 +1,3 @@
module Stepford
- VERSION = '0.8.0'
+ VERSION = '0.8.1'
end

0 comments on commit 1d6dcbc

Please sign in to comment.