Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added :add_headers option to verify which merges a hash of name/value…

… pairs into the response's headers hash if the prerequisites cannot be satisfied

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4201 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 23585d721d5da714c94b82905d38c7b77a67402a 1 parent 47b74e6
Sam Stephenson sstephenson authored
5 actionpack/CHANGELOG
View
@@ -1,5 +1,10 @@
*SVN*
+* Added :add_headers option to verify which merges a hash of name/value pairs into the response's headers hash if the prerequisites cannot be satisfied. [Sam Stephenson]
+ ex. verify :only => :speak, :method => :post,
+ :render => { :status => 405, :text => "Must be post" },
+ :add_headers => { "Allow" => "POST" }
+
* Added ActionController.filter_parameter_logging that makes it easy to remove passwords, credit card numbers, and other sensitive information from being logged when a request is handled #1897 [jeremye@bsa.ca.gov]
4 actionpack/lib/action_controller/verification.rb
View
@@ -51,6 +51,9 @@ module ClassMethods
# from an Ajax call or not.
# * <tt>:add_flash</tt>: a hash of name/value pairs that should be merged
# into the session's flash if the prerequisites cannot be satisfied.
+ # * <tt>:add_headers</tt>: a hash of name/value pairs that should be
+ # merged into the response's headers hash if the prerequisites cannot
+ # be satisfied.
# * <tt>:redirect_to</tt>: the redirection parameters to be used when
# redirecting if the prerequisites cannot be satisfied.
# * <tt>:render</tt>: the render parameters to be used when
@@ -82,6 +85,7 @@ def verify_action(options) #:nodoc:
if prereqs_invalid
flash.update(options[:add_flash]) if options[:add_flash]
+ response.headers.update(options[:add_headers]) if options[:add_headers]
unless performed?
render(options[:render]) if options[:render]
redirect_to(options[:redirect_to]) if options[:redirect_to]
8 actionpack/test/controller/verification_test.rb
View
@@ -31,7 +31,7 @@ class TestController < ActionController::Base
verify :only => :two_redirects, :method => :post,
:redirect_to => { :action => "unguarded" }
- verify :only => :must_be_post, :method => :post, :render => { :status => 500, :text => "Must be post"}
+ verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
def guarded_one
render :text => "#{@params["one"]}"
@@ -212,13 +212,13 @@ def test_guarded_post_and_calls_render_succeeds
assert_equal "Was a post!", @response.body
end
- def test_guarded_post_and_calls_render_fails
+ def test_guarded_post_and_calls_render_fails_and_sets_allow_header
get :must_be_post
- assert_response 500
+ assert_response 405
assert_equal "Must be post", @response.body
+ assert_equal "POST", @response.headers["Allow"]
end
-
def test_second_redirect
assert_nothing_raised { get :two_redirects }
end
Please sign in to comment.
Something went wrong with that request. Please try again.