aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-04-03 20:23:23 -0700
committerwycats <wycats@gmail.com>2010-04-03 20:24:30 -0700
commitab8bf9e152ad75c8b358c85e4c95cfde578de127 (patch)
tree1e5887a4c0bdbf0750c359dc8d1c6d2d5585a5bf /actionpack/test
parent512b4bccfbe222bd7f94adf6f9af07c2e856767d (diff)
downloadrails-ab8bf9e152ad75c8b358c85e4c95cfde578de127.tar.gz
rails-ab8bf9e152ad75c8b358c85e4c95cfde578de127.tar.bz2
rails-ab8bf9e152ad75c8b358c85e4c95cfde578de127.zip
* Change the object used in routing constraints to be an instance of
ActionDispatch::Request rather than Rack::Request. * Changed ActionDispatch::Request#method to return a String, to be compatible with the Rack::Request superclass. * Changed ActionDispatch::Request#method to return the original method in the case of methodoverride and #request_method not to, to be compatible with Rack::Request
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/integration_test.rb2
-rw-r--r--actionpack/test/controller/verification_test.rb2
-rw-r--r--actionpack/test/dispatch/rack_test.rb2
-rw-r--r--actionpack/test/dispatch/request_test.rb20
-rw-r--r--actionpack/test/dispatch/routing_test.rb57
5 files changed, 74 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..bb7c322790 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -187,6 +187,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