stepford 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +17 -5
- data/lib/stepford/factory_girl.rb +2 -1
- data/lib/stepford/version.rb +1 -1
- metadata +1 -1
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/stepford/version.rb
CHANGED