Skip to content

Commit

Permalink
version 0.2.3. handles more column types, more info in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
garysweaver committed Nov 2, 2012
1 parent eff0b82 commit 9b6dfaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ If you are using STI, you'll need to manually fix the value that goes into the `

Tested with postgreSQL 9.x only.

If you use stepford to create factories for existing tests and the tests fail with:

ActiveRecord::StatementInvalid:
PG::Error: ERROR: null value in column "something_id" violates not-null constraint

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.

If you specify `--associations`, you might get circular associations and could easily end up with:

SystemStackError:
Expand Down
15 changes: 7 additions & 8 deletions lib/stepford/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Stepford
class Common
def self.value_for(column)
case column.type
when :string
when :string, :text
if column.default.nil?
result = "Test #{column.name.titleize}"
column.limit && column.limit < result.size ? (column.limit >= 0 ? "'#{'a' * column.limit}'" : 'nil') : "'#{result}'"
Expand All @@ -11,22 +11,21 @@ def self.value_for(column)
end
when :integer
column.default.nil? ? (column.limit ? column.limit.to_s : '123') : column.default.to_s
when :decimal
when :decimal, :float
column.default.nil? ? (column.limit ? column.limit.to_s : '1.23') : column.default.to_s
when :datetime
'{ 2.weeks.ago }'
when :timestamp
when :date, :datetime, :timestamp
'{ 2.weeks.ago }'
when :binary
column.default.nil? ? (column.limit ? column.limit.to_s : '0b010101') : column.default.to_s
when :boolean
column.default.nil? ? 'true' : column.default.to_s
when :xml
'<test>Test #{column_name.titleize}</test>'
column.default.nil? ? '<test>Test #{column_name.titleize}</test>' : column.default.to_s
when :ts_vector
'nil'
column.default.nil? ? 'nil' : column.default.to_s
else
'nil'
puts "Stepford does not know how to handle type #{column.type.to_sym}"
column.default.nil? ? 'nil' : column.default.to_s
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stepford/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Stepford
VERSION = '0.2.2'
VERSION = '0.2.3'
end

0 comments on commit 9b6dfaa

Please sign in to comment.