1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Support :render option to :verify #1440 [TobiasLuetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1418 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2005-06-14 13:23:55 +00:00
parent b2b757be39
commit 75fb0a32a8
3 changed files with 25 additions and 2 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Support :render option for :verify #1440 [TobiasLuetke]
* Updated vendor copy of html-scanner lib to 0.5.1, for bug fixes and optimizations
* Changed test requests to come from 0.0.0.0 instead of 127.0.0.1 such that they don't trigger debugging screens on exceptions, but instead call rescue_action_in_public

View file

@ -52,6 +52,8 @@ module ActionController #:nodoc:
# into the session's flash 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
# the prerequisites cannot be satisfied.
# * <tt>:only</tt>: only apply this verification to the actions specified
# in the associated array (may also be a single value).
# * <tt>:except</tt>: do not apply this verification to the actions
@ -77,7 +79,10 @@ module ActionController #:nodoc:
if prereqs_invalid
flash.update(options[:add_flash]) if options[:add_flash]
redirect_to(options[:redirect_to]) if options[:redirect_to] unless performed?
unless performed?
render(options[:render]) if options[:render]
redirect_to(options[:redirect_to]) if options[:redirect_to]
end
return false
end

View file

@ -25,6 +25,8 @@ class VerificationTest < Test::Unit::TestCase
verify :only => :two_redirects, :method => :post,
:redirect_to => { :action => "unguarded" }
verify :only => :must_be_post, :method => :post, :render => { :status => 500, :text => "Must be post"}
def guarded_one
render :text => "#{@params["one"]}"
end
@ -60,7 +62,11 @@ class VerificationTest < Test::Unit::TestCase
def two_redirects
render :nothing => true
end
def must_be_post
render :text => "Was a post!"
end
protected
def rescue_action(e) raise end
@ -166,6 +172,16 @@ class VerificationTest < Test::Unit::TestCase
get :guarded_by_method
assert_redirected_to :action => "unguarded"
end
def test_guarded_post_and_calls_render
post :must_be_post
assert_equal "Was a post!", @response.body
get :must_be_post
assert_response 500
assert_equal "Must be post", @response.body
end
def test_second_redirect
assert_nothing_raised { get :two_redirects }