stepford 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
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 and that it should create a factory file for each model with non-primary key, non-foreign key attributes only, and no associations:
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
- 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.
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 it.
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
 
@@ -1,21 +1,26 @@
1
1
  module Stepford
2
2
  class Common
3
- def self.value_for(column_name, type)
4
- case type
3
+ def self.value_for(column)
4
+ case column.type
5
5
  when :string
6
- "'Test #{column_name.titleize}'"
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.name, c.type)}" unless foreign_keys.include?(c.name.to_sym) || primary_keys.include?(c.name.to_sym)}.compact.sort.each {|l|factory << l}
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]
@@ -1,3 +1,3 @@
1
1
  module Stepford
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
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.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: