Permalink
Browse files

Use GeneratedAttribute#column_name if #reference? scaffold_generator …

…in _form view [Fixes #11573]
  • Loading branch information...
1 parent eb8d48e commit b017562382e1c43655eec3456d2a78c1d4407952 @zzak zzak committed with spastorino Jul 23, 2013
@@ -21,8 +21,13 @@
<%%= f.label :password_confirmation %><br>
<%%= f.password_field :password_confirmation %>
<% else -%>
+ <% if attribute.reference? -%>
+ <%%= f.label :<%= attribute.column_name %> %><br>
+ <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %>
+ <% else -%>
<%%= f.label :<%= attribute.name %> %><br>
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
+ <% end -%>
<% end -%>
</div>
<% end -%>
@@ -286,6 +286,30 @@ def test_scaffold_generator_outputs_error_message_on_missing_attribute_type
end
end
+ def test_scaffold_generator_belongs_to
+ run_generator ["account", "name", "currency:belongs_to"]
+
+ assert_file "app/models/account.rb", /belongs_to :currency/
+
+ assert_migration "db/migrate/create_accounts.rb" do |m|
+ assert_method :change, m do |up|
+ assert_match(/t\.string :name/, up)
+ assert_match(/t\.belongs_to :currency/, up)
+ end
+ end
+
+ assert_file "app/controllers/accounts_controller.rb" do |content|
+ assert_instance_method :account_params, content do |m|
+ assert_match(/permit\(:name, :currency_id\)/, m)
+ end
+ end
+
+ assert_file "app/views/accounts/_form.html.erb" do |content|
+ assert_match(/<%= f\.text_field :name %>/, content)
+ assert_match(/<%= f\.text_field :currency_id %>/, content)
+ end
+ end
+
def test_scaffold_generator_password_digest
run_generator ["user", "name", "password:digest"]

0 comments on commit b017562

Please sign in to comment.