diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index b2bcaf63be..7625ff975c 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -4,13 +4,17 @@ one: <% attributes.each do |attribute| -%> <%= attribute.column_name %>: <%= attribute.default %> - <%= "#{attribute.name}_type: #{attribute.human_name}" if attribute.polymorphic? %> + <%- if attribute.polymorphic? -%> + <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%- end -%> <% end -%> two: <% attributes.each do |attribute| -%> <%= attribute.column_name %>: <%= attribute.default %> - <%= "#{attribute.name}_type: #{attribute.human_name}" if attribute.polymorphic? %> + <%- if attribute.polymorphic? -%> + <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%- end -%> <% end -%> <% else -%> # This model initially had no columns defined. If you add columns to the diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 0fbaf0c9bb..70e080a8ab 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -275,12 +275,12 @@ class ModelGeneratorTest < Rails::Generators::TestCase def test_fixtures_use_the_references_ids run_generator ["LineItem", "product:references", "cart:belongs_to"] - assert_file "test/fixtures/line_items.yml", /product_id: /, /cart_id: / + assert_file "test/fixtures/line_items.yml", /product_id: \n cart_id: / end def test_fixtures_use_the_references_ids_and_type run_generator ["LineItem", "product:references{polymorphic}", "cart:belongs_to"] - assert_file "test/fixtures/line_items.yml", /product_id: /, /product_type: Product/, /cart_id: / + assert_file "test/fixtures/line_items.yml", /product_id: \n product_type: Product\n cart_id: / end def test_fixture_is_skipped