提交 b0175623 编写于 作者: Z Zachary Scott 提交者: Santiago Pastorino

Use GeneratedAttribute#column_name if #reference? scaffold_generator in _form view [Fixes #11573]

上级 eb8d48eb
......@@ -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"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册