aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/configuration_test.rb
diff options
context:
space:
mode:
authorDavid Lee <davidomundo@gmail.com>2011-05-06 14:03:55 -0700
committerDavid Lee <davidomundo@gmail.com>2012-02-22 08:47:10 -0800
commit002713c64568114f3754799acc0723ea0d442f7a (patch)
treebd01c3ded14a9a96b92fbb54b8e0da35a899e374 /railties/test/application/configuration_test.rb
parent66b7eb19279820b6464ad2b9e3f2efadb08f2ff2 (diff)
downloadrails-002713c64568114f3754799acc0723ea0d442f7a.tar.gz
rails-002713c64568114f3754799acc0723ea0d442f7a.tar.bz2
rails-002713c64568114f3754799acc0723ea0d442f7a.zip
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.
Diffstat (limited to 'railties/test/application/configuration_test.rb')
-rw-r--r--railties/test/application/configuration_test.rb47
1 files changed, 45 insertions, 2 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 3dffd1c74c..bf44a8b10b 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -146,7 +146,7 @@ module ApplicationTests
test "frameworks are not preloaded by default" do
require "#{app_path}/config/environment"
- assert ActionController.autoload?(:RecordIdentifier)
+ assert ActionController.autoload?(:Caching)
end
test "frameworks are preloaded with config.preload_frameworks is set" do
@@ -156,7 +156,7 @@ module ApplicationTests
require "#{app_path}/config/environment"
- assert !ActionController.autoload?(:RecordIdentifier)
+ assert !ActionController.autoload?(:Caching)
end
test "filter_parameters should be able to set via config.filter_parameters" do
@@ -246,6 +246,49 @@ module ApplicationTests
assert last_response.body =~ /csrf\-param/
end
+ test "default method for update can be changed" do
+ app_file 'app/models/post.rb', <<-RUBY
+ class Post
+ extend ActiveModel::Naming
+ def to_key; [1]; end
+ def persisted?; true; end
+ end
+ RUBY
+
+ app_file 'app/controllers/posts_controller.rb', <<-RUBY
+ class PostsController < ApplicationController
+ def show
+ render :inline => "<%= begin; form_for(Post.new) {}; rescue => e; e.to_s; end %>"
+ end
+
+ def update
+ render :text => "update"
+ end
+ end
+ RUBY
+
+ add_to_config <<-RUBY
+ config.default_method_for_update = :patch
+ routes.prepend do
+ resources :posts
+ end
+ RUBY
+
+ require "#{app_path}/config/environment"
+
+ assert_equal ActionView::Base.default_method_for_update, :patch
+ assert_equal ActionDispatch::Routing::Mapper.default_method_for_update, :patch
+
+ get "/posts/1"
+ assert_match /patch/, last_response.body
+
+ patch "/posts/1"
+ assert_match /update/, last_response.body
+
+ put "/posts/1"
+ assert_equal 404, last_response.status
+ end
+
test "request forgery token param can be changed" do
make_basic_app do
app.config.action_controller.request_forgery_protection_token = '_xsrf_token_here'