Skip to content
Browse files

Make references and belongs_to attributes to generate the _id column in

fixtures
  • Loading branch information...
1 parent 3d8fcdd commit 4a487f94b9812964e644716f301ab287dea8cddc @rafaelfranca rafaelfranca committed Dec 9, 2012
View
4 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
View
5 railties/test/generators/model_generator_test.rb
@@ -273,6 +273,11 @@ def test_invokes_default_test_framework
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"

0 comments on commit 4a487f9

Please sign in to comment.
Something went wrong with that request. Please try again.