diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/verification_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/rack_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 68 |
5 files changed, 85 insertions, 9 deletions
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 1e2ee06adc..14c0c3708b 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -236,7 +236,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest end def method - render :text => "method: #{request.method}" + render :text => "method: #{request.method.downcase}" end def cookie_monster diff --git a/actionpack/test/controller/verification_test.rb b/actionpack/test/controller/verification_test.rb index 11d0d10897..0600ec2ec1 100644 --- a/actionpack/test/controller/verification_test.rb +++ b/actionpack/test/controller/verification_test.rb @@ -71,7 +71,7 @@ class VerificationTest < ActionController::TestCase end def guarded_by_method - render :text => "#{request.method}" + render :text => "#{request.method.downcase}" end def guarded_by_xhr diff --git a/actionpack/test/dispatch/rack_test.rb b/actionpack/test/dispatch/rack_test.rb index 504bebbb86..698f980296 100644 --- a/actionpack/test/dispatch/rack_test.rb +++ b/actionpack/test/dispatch/rack_test.rb @@ -142,7 +142,7 @@ class RackRequestTest < BaseRackTest assert_equal "google.com", @request.remote_host assert_equal "kevin", @request.remote_ident assert_equal "kevin", @request.remote_user - assert_equal :get, @request.request_method + assert_equal "GET", @request.request_method assert_equal "/dispatch.fcgi", @request.script_name assert_equal "glu.ttono.us", @request.server_name assert_equal 8007, @request.server_port diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 9093e1ed65..e5ee412021 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -223,10 +223,17 @@ class RequestTest < ActiveSupport::TestCase assert request.ssl? end - test "symbolized request methods" do + test "String request methods" do [:get, :post, :put, :delete].each do |method| request = stub_request 'REQUEST_METHOD' => method.to_s.upcase - assert_equal method, request.method + assert_equal method.to_s.upcase, request.method + end + end + + test "Symbol forms of request methods via method_symbol" do + [:get, :post, :put, :delete].each do |method| + request = stub_request 'REQUEST_METHOD' => method.to_s.upcase + assert_equal method, request.method_symbol end end @@ -238,9 +245,9 @@ class RequestTest < ActiveSupport::TestCase end test "allow method hacking on post" do - [:get, :options, :put, :post, :delete].each do |method| + %w(GET OPTIONS PUT POST DELETE).each do |method| request = stub_request "REQUEST_METHOD" => method.to_s.upcase - assert_equal(method == :head ? :get : method, request.method) + assert_equal(method == "HEAD" ? "GET" : method, request.method) end end @@ -255,13 +262,14 @@ class RequestTest < ActiveSupport::TestCase [:get, :put, :delete].each do |method| request = stub_request 'REQUEST_METHOD' => method.to_s.upcase, 'action_dispatch.request.request_parameters' => { :_method => 'put' } - assert_equal method, request.method + assert_equal method.to_s.upcase, request.method end end test "head masquerading as get" do request = stub_request 'REQUEST_METHOD' => 'GET', "rack.methodoverride.original_method" => "HEAD" - assert_equal :get, request.method + assert_equal "HEAD", request.method + assert_equal "GET", request.request_method assert request.get? assert request.head? end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 19538cb88b..6ff478aec1 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -39,6 +39,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'account/modulo/:name', :to => redirect("/%{name}s") match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" } + match 'account/proc_req' => redirect {|params, req| "/#{req.method}" } + match 'account/google' => redirect('http://www.google.com/') match 'openid/login', :via => [:get, :post], :to => "openid#login" @@ -187,6 +189,63 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + class TestAltApp < ActionController::IntegrationTest + class AltRequest + def initialize(env) + @env = env + end + + def path_info + "/" + end + + def request_method + "GET" + end + + def x_header + @env["HTTP_X_HEADER"] || "" + end + end + + class XHeader + def call(env) + [200, {"Content-Type" => "text/html"}, ["XHeader"]] + end + end + + class AltApp + def call(env) + [200, {"Content-Type" => "text/html"}, ["Alternative App"]] + end + end + + AltRoutes = ActionDispatch::Routing::RouteSet.new(AltRequest) + AltRoutes.draw do + get "/" => XHeader.new, :constraints => {:x_header => /HEADER/} + get "/" => AltApp.new + end + + def app + AltRoutes + end + + def test_alt_request_without_header + get "/" + assert_equal "Alternative App", @response.body + end + + def test_alt_request_with_matched_header + get "/", {}, "HTTP_X_HEADER" => "HEADER" + assert_equal "XHeader", @response.body + end + + def test_alt_request_with_unmatched_header + get "/", {}, "HTTP_X_HEADER" => "NON_MATCH" + assert_equal "Alternative App", @response.body + end + end + def app Routes end @@ -294,6 +353,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_redirect_proc_with_request + with_test_routes do + get '/account/proc_req' + assert_equal 301, @response.status + assert_equal 'http://www.example.com/GET', @response.headers['Location'] + assert_equal 'Moved Permanently', @response.body + end + end + def test_openid with_test_routes do get '/openid/login' |