From eeb58b0934f646847b3220e3db270bc6b9148919 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Sat, 5 Mar 2011 16:25:20 -0500 Subject: [PATCH] Generate valid default fixtures for models with a type column Signed-off-by: Santiago Pastorino --- railties/lib/rails/generators/generated_attribute.rb | 2 +- railties/test/generators/generated_attribute_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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