From b7a094536de6fdeb428aa79d21f1e2128169f45e Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 24 Feb 2012 16:25:41 -0800 Subject: uses PATCH for the forms of persisted records, and routes PATCH and PUT to the update action of resources --- actionpack/test/dispatch/routing_test.rb | 8 ++ actionpack/test/template/form_helper_test.rb | 135 +++++++++++++-------------- 2 files changed, 74 insertions(+), 69 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index e8da790e50..eb495d30e5 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1026,6 +1026,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal 'pasts#destroy', @response.body assert_equal '/past', past_path + patch '/present' + assert_equal 'presents#update', @response.body + assert_equal '/present', present_path + put '/present' assert_equal 'presents#update', @response.body assert_equal '/present', present_path @@ -1044,6 +1048,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal 'relationships#destroy', @response.body assert_equal '/relationships/1', relationship_path(1) + patch '/friendships/1' + assert_equal 'friendships#update', @response.body + assert_equal '/friendships/1', friendship_path(1) + put '/friendships/1' assert_equal 'friendships#update', @response.body assert_equal '/friendships/1', friendship_path(1) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 61d728ce66..3546bd3bee 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -181,7 +181,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do + expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch') do "" end @@ -198,7 +198,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do + expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch') do "" end @@ -758,7 +758,7 @@ class FormHelperTest < ActionView::TestCase concat f.button('Create post') end - expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do + expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch') do "" + "" + "" + @@ -778,7 +778,7 @@ class FormHelperTest < ActionView::TestCase concat f.file_field(:file) end - expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put", :multipart => true) do + expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch', :multipart => true) do "" end @@ -794,7 +794,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form("/posts/123", "edit_post_123" , "edit_post", :method => "put", :multipart => true) do + expected = whole_form("/posts/123", "edit_post_123" , "edit_post", :method => 'patch', :multipart => true) do "" end @@ -807,7 +807,7 @@ class FormHelperTest < ActionView::TestCase concat f.label(:title) end - expected = whole_form("/posts/123.json", "edit_post_123" , "edit_post", :method => "put") do + expected = whole_form("/posts/123.json", "edit_post_123" , "edit_post", :method => 'patch') do "" end @@ -820,7 +820,7 @@ class FormHelperTest < ActionView::TestCase concat f.submit('Edit post') end - expected = whole_form("/posts/44", "edit_post_44" , "edit_post", :method => "put") do + expected = whole_form("/posts/44", "edit_post_44" , "edit_post", :method => 'patch') do "" + "" end @@ -837,7 +837,7 @@ class FormHelperTest < ActionView::TestCase concat f.submit('Create post') end - expected = whole_form("/posts/123", "create-post", "edit_other_name", :method => "put") do + expected = whole_form("/posts/123", "create-post", "edit_other_name", :method => 'patch') do "" + "" + "" + @@ -898,13 +898,13 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_remote - form_for(@post, :url => '/', :remote => true, :html => { :id => 'create-post', :method => :put }) do |f| + form_for(@post, :url => '/', :remote => true, :html => { :id => 'create-post', :method => :patch}) do |f| concat f.text_field(:title) concat f.text_area(:body) concat f.check_box(:secret) end - expected = whole_form("/", "create-post", "edit_post", :method => "put", :remote => true) do + expected = whole_form("/", "create-post", "edit_post", :method => 'patch', :remote => true) do "" + "" + "" + @@ -915,13 +915,13 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_remote_in_html - form_for(@post, :url => '/', :html => { :remote => true, :id => 'create-post', :method => :put }) do |f| + form_for(@post, :url => '/', :html => { :remote => true, :id => 'create-post', :method => :patch }) do |f| concat f.text_field(:title) concat f.text_area(:body) concat f.check_box(:secret) end - expected = whole_form("/", "create-post", "edit_post", :method => "put", :remote => true) do + expected = whole_form("/", "create-post", "edit_post", :method => 'patch', :remote => true) do "" + "" + "" + @@ -975,7 +975,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'patch') do "" + "" + "" + @@ -993,7 +993,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'patch') do "" + "" + "" + @@ -1010,7 +1010,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'patch') do "" + "" + "" + @@ -1026,7 +1026,7 @@ class FormHelperTest < ActionView::TestCase concat f.text_field(:title) end - expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'patch') do "" + "" end @@ -1040,7 +1040,7 @@ class FormHelperTest < ActionView::TestCase concat f.text_field(:title) end - expected_1 = whole_form('/posts/123', 'namespace_1_edit_post_123', 'edit_post', 'put') do + expected_1 = whole_form('/posts/123', 'namespace_1_edit_post_123', 'edit_post', 'patch') do "" + "" end @@ -1052,7 +1052,7 @@ class FormHelperTest < ActionView::TestCase concat f.text_field(:title) end - expected_2 = whole_form('/posts/123', 'namespace_2_edit_post_123', 'edit_post', 'put') do + expected_2 = whole_form('/posts/123', 'namespace_2_edit_post_123', 'edit_post', 'patch') do "" + "" end @@ -1070,7 +1070,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'namespace_edit_post_123', 'edit_post', 'patch') do "" + "" + "" @@ -1104,7 +1104,7 @@ class FormHelperTest < ActionView::TestCase concat f.submit end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do "" end @@ -1136,7 +1136,7 @@ class FormHelperTest < ActionView::TestCase concat f.submit end - expected = whole_form('/posts/123', 'edit_another_post', 'edit_another_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_another_post', 'edit_another_post', :method => 'patch') do "" end @@ -1153,7 +1153,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do "" end @@ -1168,7 +1168,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'patch') do "" + "" end @@ -1184,7 +1184,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'patch') do "" + "" end @@ -1199,7 +1199,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'patch') do "" end @@ -1213,7 +1213,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'patch') do "" end @@ -1227,7 +1227,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'patch') do "" end @@ -1241,7 +1241,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'patch') do "" end @@ -1255,7 +1255,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'patch') do "" end @@ -1275,9 +1275,9 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'put') do + expected = whole_form('/posts/123', 'edit_post[]', 'edit_post[]', 'patch') do "" - end + whole_form('/posts/123', 'edit_post', 'edit_post', 'put') do + end + whole_form('/posts/123', 'edit_post', 'edit_post', 'patch') do "" end @@ -1294,7 +1294,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' end @@ -1321,7 +1321,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' @@ -1340,7 +1340,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' @@ -1359,7 +1359,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' end @@ -1377,7 +1377,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' end @@ -1395,7 +1395,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' @@ -1415,7 +1415,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' @@ -1436,7 +1436,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1463,7 +1463,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1490,7 +1490,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1516,7 +1516,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1539,7 +1539,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1563,7 +1563,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1586,7 +1586,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' @@ -1607,7 +1607,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1625,7 +1625,7 @@ class FormHelperTest < ActionView::TestCase end end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' end @@ -1642,7 +1642,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1663,7 +1663,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1685,7 +1685,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1708,7 +1708,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1728,7 +1728,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' end @@ -1764,7 +1764,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' + '' + '' + @@ -1791,7 +1791,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do '' end @@ -1930,7 +1930,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'create-post', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'create-post', 'edit_post', :method => 'patch') do "" + "" + "" + @@ -1950,7 +1950,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'create-post', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'create-post', 'edit_post', :method => 'patch') do "" + "" + "" @@ -1966,7 +1966,7 @@ class FormHelperTest < ActionView::TestCase } end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'patch') do "" end @@ -1990,7 +1990,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do "
" + "
" + "
" @@ -2040,7 +2040,7 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do "
" + "
" + "
" @@ -2120,7 +2120,7 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_html_options_adds_options_to_form_tag form_for(@post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end - expected = whole_form("/posts/123", "some_form", "some_class", 'put') + expected = whole_form("/posts/123", "some_form", "some_class", 'patch') assert_dom_equal expected, output_buffer end @@ -2128,7 +2128,7 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_string_url_option form_for(@post, :url => 'http://www.otherdomain.com') do |f| end - assert_equal whole_form("http://www.otherdomain.com", 'edit_post_123', 'edit_post', 'put'), output_buffer + assert_equal whole_form("http://www.otherdomain.com", 'edit_post_123', 'edit_post', 'patch'), output_buffer end def test_form_for_with_hash_url_option @@ -2141,14 +2141,14 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_record_url_option form_for(@post, :url => @post) do |f| end - expected = whole_form("/posts/123", 'edit_post_123', 'edit_post', 'put') + expected = whole_form("/posts/123", 'edit_post_123', 'edit_post', 'patch') assert_equal expected, output_buffer end def test_form_for_with_existing_object form_for(@post) do |f| end - expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") + expected = whole_form("/posts/123", "edit_post_123", "edit_post", 'patch') assert_equal expected, output_buffer end @@ -2167,7 +2167,7 @@ class FormHelperTest < ActionView::TestCase @comment.save form_for([@post, @comment]) {} - expected = whole_form(post_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put") + expected = whole_form(post_comment_path(@post, @comment), "edit_comment_1", "edit_comment", 'patch') assert_dom_equal expected, output_buffer end @@ -2182,7 +2182,7 @@ class FormHelperTest < ActionView::TestCase @comment.save form_for([:admin, @post, @comment]) {} - expected = whole_form(admin_post_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put") + expected = whole_form(admin_post_comment_path(@post, @comment), "edit_comment_1", "edit_comment", 'patch') assert_dom_equal expected, output_buffer end @@ -2196,17 +2196,14 @@ class FormHelperTest < ActionView::TestCase def test_form_for_with_existing_object_and_custom_url form_for(@post, :url => "/super_posts") do |f| end - expected = whole_form("/super_posts", "edit_post_123", "edit_post", "put") + expected = whole_form("/super_posts", "edit_post_123", "edit_post", 'patch') assert_equal expected, output_buffer end def test_form_for_with_default_method_as_patch - ActionView::Base.default_method_for_update = :patch form_for(@post) {} expected = whole_form("/posts/123", "edit_post_123", "edit_post", "patch") assert_dom_equal expected, output_buffer - ensure - ActionView::Base.default_method_for_update = :put end def test_fields_for_returns_block_result -- cgit v1.2.3