diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-09 14:34:26 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-10 00:01:40 -0300 |
commit | 4a487f94b9812964e644716f301ab287dea8cddc (patch) | |
tree | b57800d2ef496b1440394a0af46d9487b4fbc64d | |
parent | 3d8fcdd3bf21482e3e297a78bfdf3d02ec71eda4 (diff) | |
download | rails-4a487f94b9812964e644716f301ab287dea8cddc.tar.gz rails-4a487f94b9812964e644716f301ab287dea8cddc.tar.bz2 rails-4a487f94b9812964e644716f301ab287dea8cddc.zip |
Make references and belongs_to attributes to generate the _id column in
fixtures
-rw-r--r-- | railties/lib/rails/generators/test_unit/model/templates/fixtures.yml | 4 | ||||
-rw-r--r-- | railties/test/generators/model_generator_test.rb | 5 |
2 files changed, 7 insertions, 2 deletions
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 5c8780aa64..71f4f99d02 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -3,12 +3,12 @@ <% unless attributes.empty? -%> one: <% attributes.each do |attribute| -%> - <%= attribute.name %>: <%= attribute.default %> + <%= attribute.reference? ? "#{attribute.name}_id" : attribute.name %>: <%= attribute.default %> <% end -%> two: <% attributes.each do |attribute| -%> - <%= attribute.name %>: <%= attribute.default %> + <%= attribute.reference? ? "#{attribute.name}_id" : attribute.name %>: <%= attribute.default %> <% 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 0c7ff0ebe7..d1f669c8c4 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -273,6 +273,11 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "test/fixtures/accounts.yml", /name: MyString/, /age: 1/ end + 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: / + end + def test_fixture_is_skipped run_generator ["account", "--skip-fixture"] assert_no_file "test/fixtures/accounts.yml" |