Skip to content

Commit

Permalink
Support decimal{1,2} and decimal{1-2} and decimal{1.2} so it works fi…
Browse files Browse the repository at this point in the history
…ne with bash, zsh, etc, closes rails#4602
  • Loading branch information
josevalim committed Jan 22, 2012
1 parent 334e5ca commit ede01ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions railties/lib/rails/generators/generated_attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def parse_type_and_options(type)
case type
when /(string|text|binary|integer)\{(\d+)\}/
return $1, :limit => $2.to_i
when /decimal\{(\d+),(\d+)\}/
return :decimal, :precision => $1.to_i, :scale => $2.to_i
when /decimal\{(\d+)(,|\.|\-)(\d+)\}/
return :decimal, :precision => $1.to_i, :scale => $3.to_i
else
return type, {}
end
Expand Down
6 changes: 3 additions & 3 deletions railties/test/generators/migration_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ def test_add_migration_with_attributes_without_type_and_index

def test_add_migration_with_attributes_index_declaration_and_attribute_options
migration = "add_title_and_content_to_books"
run_generator [migration, "title:string{40}:index", "content:string{255}", "price:decimal{5,2}:index", "discount:decimal{3,2}:uniq"]
run_generator [migration, "title:string{40}:index", "content:string{255}", "price:decimal{1,2}:index", "discount:decimal{3.4}:uniq"]

assert_migration "db/migrate/#{migration}.rb" do |content|
assert_method :change, content do |up|
assert_match(/add_column :books, :title, :string, :limit => 40/, up)
assert_match(/add_column :books, :content, :string, :limit => 255/, up)
assert_match(/add_column :books, :price, :decimal,/, up)
assert_match(/, :precision => 5/, up)
assert_match(/, :precision => 1/, up)
assert_match(/, :scale => 2/, up)
assert_match(/add_column :books, :discount, :decimal,/, up)
assert_match(/, :precision => 3/, up)
assert_match(/, :scale => 2/, up)
assert_match(/, :scale => 4/, up)
end
assert_match(/add_index :books, :title/, content)
assert_match(/add_index :books, :price/, content)
Expand Down

0 comments on commit ede01ce

Please sign in to comment.