diff options
author | Pablo Olmos de Aguilera Corradini <pablo@glatelier.org> | 2015-01-02 21:36:35 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-02 23:01:24 -0300 |
commit | 9405ecdd98af9c8f0bd19c58a19798ebe364ed62 (patch) | |
tree | 48a27719163f6e61cad0dbc34b572d781b4769d4 /railties | |
parent | 3456d543eba1f29e97c6c924302ea6898d9ab1d8 (diff) | |
download | rails-9405ecdd98af9c8f0bd19c58a19798ebe364ed62.tar.gz rails-9405ecdd98af9c8f0bd19c58a19798ebe364ed62.tar.bz2 rails-9405ecdd98af9c8f0bd19c58a19798ebe364ed62.zip |
Generated fixtures won't use parent_id when generated with parent:references
Fix #18301
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/test_unit/model/templates/fixtures.yml | 2 | ||||
-rw-r--r-- | railties/test/generators/model_generator_test.rb | 10 |
2 files changed, 7 insertions, 5 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 f19e9d1d87..50ca61a35b 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -5,6 +5,8 @@ <% attributes.each do |attribute| -%> <%- if attribute.password_digest? -%> password_digest: <%%= BCrypt::Password.create('secret') %> + <%- elsif attribute.reference? -%> + <%= yaml_key_value(attribute.column_name.sub(/_id$/, ''), attribute.default) %> <%- else -%> <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- end -%> diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 9dc438fe3c..afee0a655d 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -287,18 +287,18 @@ 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: \n cart_id: / + assert_file "test/fixtures/line_items.yml", /product: \n cart: / assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"product_id"=>nil, "cart_id"=>nil}, "two"=>{"product_id"=>nil, "cart_id"=>nil}}) + {"one"=>{"product"=>nil, "cart"=>nil}, "two"=>{"product"=>nil, "cart"=>nil}}) 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: \n product_type: Product\n cart_id: / + assert_file "test/fixtures/line_items.yml", /product: \n product_type: Product\n cart: / assert_generated_fixture("test/fixtures/line_items.yml", - {"one"=>{"product_id"=>nil, "product_type"=>"Product", "cart_id"=>nil}, - "two"=>{"product_id"=>nil, "product_type"=>"Product", "cart_id"=>nil}}) + {"one"=>{"product"=>nil, "product_type"=>"Product", "cart"=>nil}, + "two"=>{"product"=>nil, "product_type"=>"Product", "cart"=>nil}}) end def test_fixtures_respect_reserved_yml_keywords |