stepford 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Stepford
2
2
  =====
3
3
 
4
+ Stepford is a CLI to create starter [Factory Girl][factory_girl] factories for all of your Rails models.
5
+
4
6
  ### Setup
5
7
 
6
8
  In your Rails 3+ project, add this to your Gemfile:
@@ -15,20 +17,30 @@ Then run:
15
17
 
16
18
  #### Factory Girl
17
19
 
18
- To automatically generate factories for [Factory Girl][factory_girl] from models, type this at command-line:
20
+ The default will assume a `test/factories` directory exists and that it should create a factory file for each model:
19
21
 
20
22
  bundle exec stepford factories
21
23
 
22
- That will create a `test/factories` directory and put a `some_model.rb` for each model into it with a starter FactoryGirl factory definition that may or may not work for you.
23
-
24
- Or, to generate a single file with all factories in `spec/factories.rb`, you'd use:
24
+ To put all of your factories into `spec/factories.rb`:
25
25
 
26
26
  bundle exec stepford factories --single --path spec
27
27
 
28
- Or it will figure it out yourself that you want a single file if the path ends in `.rb`:
28
+ It will figure out that you want a single file, if the path ends in `.rb`:
29
29
 
30
30
  bundle exec stepford factories --path spec/support/factories.rb
31
31
 
32
+ ### Stepford Checks Model Associations
33
+
34
+ Stepford first loads Rails and attempts to check your models for broken associations.
35
+
36
+ If associations are deemed broken, it will output proposed changes.
37
+
38
+ ### Troubleshooting
39
+
40
+ If you have duplicate factory definitions during Rails load, it may complain. Just move, rename, or remove the offending files and factories and retry.
41
+
42
+ Uses the Ruby 1.9 hash syntax in generated factories. If you don't have 1.9, it might not fail during generation, but it may later when loading the factories.
43
+
32
44
  ### License
33
45
 
34
46
  Copyright (c) 2012 Gary S. Weaver, released under the [MIT license][lic].
@@ -13,9 +13,10 @@ module Stepford
13
13
  model_class = model_name.camelize.constantize
14
14
  next unless model_class.ancestors.include?(ActiveRecord::Base)
15
15
  factory = (factories[model_name.to_sym] ||= [])
16
+ primary_keys = Array.wrap(model_class.primary_key).collect{|pk|pk.to_sym}
16
17
  foreign_keys = []
17
18
  model_class.reflections.collect {|a,b| (expected[b.class_name.underscore.to_sym] ||= []) << model_name; foreign_keys << b.foreign_key.to_sym; "association #{b.name.to_sym.inspect}, factory: #{b.class_name.underscore.to_sym.inspect}"}.sort.each {|l|factory << l}
18
- model_class.columns.collect {|c| "#{c.name.to_sym} #{Stepford::Common.value_for(c.name, c.type)}" unless foreign_keys.include?(c.name.to_sym)}.compact.sort.each {|l|factory << l}
19
+ model_class.columns.collect {|c| "#{c.name.to_sym} #{Stepford::Common.value_for(c.name, c.type)}" unless foreign_keys.include?(c.name.to_sym) || primary_keys.include?(c.name.to_sym)}.compact.sort.each {|l|factory << l}
19
20
  end
20
21
 
21
22
  failed = false
@@ -1,3 +1,3 @@
1
1
  module Stepford
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepford
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: