Permalink
Browse files

Use the references and belongs_id ids in the scaffold_controller

generator
  • Loading branch information...
1 parent 95b7b02 commit b4b8c26b6e3568525b974889e60bfd2a025f0114 @rafaelfranca rafaelfranca committed Dec 6, 2012
@@ -94,7 +94,7 @@ def <%= "#{singular_table_name}_params" %>
<%- if attributes.empty? -%>
params[<%= ":#{singular_table_name}" %>]
<%- else -%>
- params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes.map {|a| ":#{a.name}" }.join(', ') %>)
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes.map { |a| ":#{a.index_name}" }.join(', ') %>)
<%- end -%>
end
end
@@ -61,6 +61,15 @@ def test_dont_use_require_or_permit_if_there_are_no_attributes
end
end
+ def test_controller_permit_references_attributes
+ run_generator ["LineItem", "product:references", "cart:belongs_to"]
+
+ assert_file "app/controllers/line_items_controller.rb" do |content|
+ assert_match(/def line_item_params/, content)
+ assert_match(/params\.require\(:line_item\)\.permit\(:product_id, :cart_id\)/, content)
+ end
+ end
+
def test_helper_are_invoked_with_a_pluralized_name
run_generator
assert_file "app/helpers/users_helper.rb", /module UsersHelper/

0 comments on commit b4b8c26

Please sign in to comment.