diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2011-03-05 16:25:20 -0500 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-07-11 19:47:57 -0300 |
commit | eeb58b0934f646847b3220e3db270bc6b9148919 (patch) | |
tree | 854843083040b7f91606ac33f77bd7bd756178a4 /railties | |
parent | 1939fa3f169e4c44234aef0f336411fc01d0445f (diff) | |
download | rails-eeb58b0934f646847b3220e3db270bc6b9148919.tar.gz rails-eeb58b0934f646847b3220e3db270bc6b9148919.tar.bz2 rails-eeb58b0934f646847b3220e3db270bc6b9148919.zip |
Generate valid default fixtures for models with a type column
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/generated_attribute_test.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index f9f89c9f1d..816d82cac3 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -32,7 +32,7 @@ module Rails when :decimal then "9.99" when :datetime, :timestamp, :time then Time.now.to_s(:db) when :date then Date.today.to_s(:db) - when :string then "MyString" + when :string then name == "type" ? "" : "MyString" when :text then "MyText" when :boolean then false when :references, :belongs_to then nil diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index c9f8ab0a7b..a85829085c 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -68,6 +68,11 @@ class GeneratedAttributeTest < Rails::Generators::TestCase assert_field_default_value :string, 'MyString' end + def test_default_value_for_type + att = Rails::Generators::GeneratedAttribute.new("type", "string") + assert_equal("", att.default) + end + def test_default_value_is_text assert_field_default_value :text, 'MyText' end |