diff options
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/request_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/controller/verification_test.rb | 34 |
2 files changed, 48 insertions, 0 deletions
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index dd7c9f9d84..8980ac7520 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -210,4 +210,18 @@ class RequestTest < Test::Unit::TestCase @request.env['SERVER_SOFTWARE'] = 'lighttpd(1.1.4)' assert_equal 'lighttpd', @request.server_software end + + def test_xml_http_request + assert !@request.xml_http_request? + assert !@request.xhr? + + @request.env['HTTP_X_REQUESTED_WITH'] = "DefinitelyNotAjax1.0" + assert !@request.xml_http_request? + assert !@request.xhr? + + @request.env['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest" + assert @request.xml_http_request? + assert @request.xhr? + end + end diff --git a/actionpack/test/controller/verification_test.rb b/actionpack/test/controller/verification_test.rb index d5741526ef..fc49d5da67 100644 --- a/actionpack/test/controller/verification_test.rb +++ b/actionpack/test/controller/verification_test.rb @@ -20,6 +20,12 @@ class VerificationTest < Test::Unit::TestCase verify :only => :guarded_by_method, :method => :post, :redirect_to => { :action => "unguarded" } + + verify :only => :guarded_by_xhr, :xhr => true, + :redirect_to => { :action => "unguarded" } + + verify :only => :guarded_by_not_xhr, :xhr => false, + :redirect_to => { :action => "unguarded" } before_filter :unconditional_redirect, :only => :two_redirects verify :only => :two_redirects, :method => :post, @@ -54,6 +60,14 @@ class VerificationTest < Test::Unit::TestCase def guarded_by_method render :text => "#{@request.method}" end + + def guarded_by_xhr + render :text => "#{@request.xhr?}" + end + + def guarded_by_not_xhr + render :text => "#{@request.xhr?}" + end def unguarded render :text => "#{@params["one"]}" @@ -173,6 +187,26 @@ class VerificationTest < Test::Unit::TestCase assert_redirected_to :action => "unguarded" end + def test_guarded_by_xhr_with_prereqs + xhr :post, :guarded_by_xhr + assert_equal "true", @response.body + end + + def test_guarded_by_xhr_without_prereqs + get :guarded_by_xhr + assert_redirected_to :action => "unguarded" + end + + def test_guarded_by_not_xhr_with_prereqs + get :guarded_by_not_xhr + assert_equal "false", @response.body + end + + def test_guarded_by_not_xhr_without_prereqs + xhr :post, :guarded_by_not_xhr + assert_redirected_to :action => "unguarded" + end + def test_guarded_post_and_calls_render post :must_be_post assert_equal "Was a post!", @response.body |