stepford 0.2.1 → 0.2.2
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 +5 -3
- data/lib/stepford/common.rb +12 -7
- data/lib/stepford/factory_girl.rb +1 -1
- data/lib/stepford/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -37,7 +37,7 @@ Then run:
|
|
37
37
|
|
38
38
|
#### Factory Girl
|
39
39
|
|
40
|
-
The default will assume a `test/factories` directory exists
|
40
|
+
The default will assume a `test/factories` directory exists. In that directory, it will create a factory file for each model containing example values for non-primary key, non-foreign key attributes only (no associations):
|
41
41
|
|
42
42
|
bundle exec stepford factories
|
43
43
|
|
@@ -65,9 +65,11 @@ If associations are deemed broken, it will output proposed changes.
|
|
65
65
|
|
66
66
|
If you have duplicate factory definitions during Rails load, it may complain. Just move, rename, or remove the offending files and factories and retry.
|
67
67
|
|
68
|
-
|
68
|
+
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.
|
69
69
|
|
70
|
-
If you are using STI, you'll need to manually fix the value that goes into the `type` attribute, or remove
|
70
|
+
If you are using STI, you'll need to manually fix the value that goes into the `type` attribute, or you can remove those.
|
71
|
+
|
72
|
+
Tested with postgreSQL 9.x only.
|
71
73
|
|
72
74
|
If you specify `--associations`, you might get circular associations and could easily end up with:
|
73
75
|
|
data/lib/stepford/common.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
module Stepford
|
2
2
|
class Common
|
3
|
-
def self.value_for(
|
4
|
-
case type
|
3
|
+
def self.value_for(column)
|
4
|
+
case column.type
|
5
5
|
when :string
|
6
|
-
|
6
|
+
if column.default.nil?
|
7
|
+
result = "Test #{column.name.titleize}"
|
8
|
+
column.limit && column.limit < result.size ? (column.limit >= 0 ? "'#{'a' * column.limit}'" : 'nil') : "'#{result}'"
|
9
|
+
else
|
10
|
+
"'#{column.default}'"
|
11
|
+
end
|
7
12
|
when :integer
|
8
|
-
'123'
|
13
|
+
column.default.nil? ? (column.limit ? column.limit.to_s : '123') : column.default.to_s
|
9
14
|
when :decimal
|
10
|
-
'1.23'
|
15
|
+
column.default.nil? ? (column.limit ? column.limit.to_s : '1.23') : column.default.to_s
|
11
16
|
when :datetime
|
12
17
|
'{ 2.weeks.ago }'
|
13
18
|
when :timestamp
|
14
19
|
'{ 2.weeks.ago }'
|
15
20
|
when :binary
|
16
|
-
'0b010101'
|
21
|
+
column.default.nil? ? (column.limit ? column.limit.to_s : '0b010101') : column.default.to_s
|
17
22
|
when :boolean
|
18
|
-
'true'
|
23
|
+
column.default.nil? ? 'true' : column.default.to_s
|
19
24
|
when :xml
|
20
25
|
'<test>Test #{column_name.titleize}</test>'
|
21
26
|
when :ts_vector
|
@@ -32,7 +32,7 @@ module Stepford
|
|
32
32
|
nil
|
33
33
|
end
|
34
34
|
}.compact.sort.each {|l|factory << l}
|
35
|
-
model_class.columns.collect {|c| "#{c.name.to_sym} #{Stepford::Common.value_for(c
|
35
|
+
model_class.columns.collect {|c| "#{c.name.to_sym} #{Stepford::Common.value_for(c)}" unless foreign_keys.include?(c.name.to_sym) || primary_keys.include?(c.name.to_sym)}.compact.sort.each {|l|factory << l}
|
36
36
|
end
|
37
37
|
|
38
38
|
if options[:associations] || options[:validate_associations]
|
data/lib/stepford/version.rb
CHANGED