From 002713c64568114f3754799acc0723ea0d442f7a Mon Sep 17 00:00:00 2001 From: David Lee Date: Fri, 6 May 2011 14:03:55 -0700 Subject: Add config.default_method_for_update to support PATCH PATCH is the correct HTML verb to map to the #update action. The semantics for PATCH allows for partial updates, whereas PUT requires a complete replacement. Changes: * adds config.default_method_for_update you can set to :patch * optionally use PATCH instead of PUT in resource routes and forms * adds the #patch verb to routes to detect PATCH requests * adds #patch? to Request * changes documentation and comments to indicate support for PATCH This change maintains complete backwards compatibility by keeping :put as the default for config.default_method_for_update. --- activeresource/test/cases/format_test.rb | 12 ++++++++---- activeresource/test/cases/http_mock_test.rb | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'activeresource/test') diff --git a/activeresource/test/cases/format_test.rb b/activeresource/test/cases/format_test.rb index 30342ecc74..315f9db1eb 100644 --- a/activeresource/test/cases/format_test.rb +++ b/activeresource/test/cases/format_test.rb @@ -11,11 +11,15 @@ class FormatTest < ActiveSupport::TestCase end def test_http_format_header_name - header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:get] - assert_equal 'Accept', header_name + [:get, :head].each do |verb| + header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[verb] + assert_equal 'Accept', header_name + end - headers_names = [ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:put], ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[:post]] - headers_names.each{ |name| assert_equal 'Content-Type', name } + [:patch, :put, :post].each do |verb| + header_name = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[verb] + assert_equal 'Content-Type', header_name + end end def test_formats_on_single_element diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb index d2fd911314..d13d9258ce 100644 --- a/activeresource/test/cases/http_mock_test.rb +++ b/activeresource/test/cases/http_mock_test.rb @@ -8,7 +8,7 @@ class HttpMockTest < ActiveSupport::TestCase FORMAT_HEADER = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES - [:post, :put, :get, :delete, :head].each do |method| + [:post, :patch, :put, :get, :delete, :head].each do |method| test "responds to simple #{method} request" do ActiveResource::HttpMock.respond_to do |mock| mock.send(method, "/people/1", { FORMAT_HEADER[method] => "application/json" }, "Response") @@ -193,7 +193,7 @@ class HttpMockTest < ActiveSupport::TestCase end def request(method, path, headers = {}, body = nil) - if method.in?([:put, :post]) + if method.in?([:patch, :put, :post]) @http.send(method, path, body, headers) else @http.send(method, path, headers) -- cgit v1.2.3