aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2008-12-09 01:38:17 +0100
committerHongli Lai (Phusion) <hongli@phusion.nl>2008-12-09 01:38:17 +0100
commit13c6c3cfc59ff0b400b294dce15f32752b0fb5f5 (patch)
tree052ac9c8f4adb91a4b32e3b2a97b1bc6bdace2e6 /actionpack/test/controller
parentccb96f2297e8783165cba764e9b5d51e1a15ff87 (diff)
parent4e60eebae05aeec65e4894e3901c9d61c9b32910 (diff)
downloadrails-13c6c3cfc59ff0b400b294dce15f32752b0fb5f5.tar.gz
rails-13c6c3cfc59ff0b400b294dce15f32752b0fb5f5.tar.bz2
rails-13c6c3cfc59ff0b400b294dce15f32752b0fb5f5.zip
Merge commit 'origin/master' into savepoints
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/caching_test.rb4
-rw-r--r--actionpack/test/controller/cgi_test.rb262
-rw-r--r--actionpack/test/controller/dispatcher_test.rb38
-rw-r--r--actionpack/test/controller/integration_test.rb47
-rw-r--r--actionpack/test/controller/rack_test.rb18
-rw-r--r--actionpack/test/controller/render_test.rb26
-rw-r--r--actionpack/test/controller/request_test.rb4
-rw-r--r--actionpack/test/controller/session_fixation_test.rb93
-rw-r--r--actionpack/test/controller/view_paths_test.rb26
-rw-r--r--actionpack/test/controller/webservice_test.rb322
10 files changed, 292 insertions, 548 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 10c65acd9a..7e7f488df6 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -67,7 +67,7 @@ class PageCachingTest < ActionController::TestCase
def teardown
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
-
+ ActionController::Routing::Routes.clear!
ActionController::Base.perform_caching = false
end
@@ -401,7 +401,7 @@ class ActionCacheTest < ActionController::TestCase
def test_xml_version_of_resource_is_treated_as_different_cache
with_routing do |set|
- ActionController::Routing::Routes.draw do |map|
+ set.draw do |map|
map.connect ':controller/:action.:format'
map.connect ':controller/:action'
end
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
deleted file mode 100644
index ac1c8abc59..0000000000
--- a/actionpack/test/controller/cgi_test.rb
+++ /dev/null
@@ -1,262 +0,0 @@
-require 'abstract_unit'
-
-class BaseCgiTest < Test::Unit::TestCase
- def setup
- @request_hash = {
- "HTTP_MAX_FORWARDS" => "10",
- "SERVER_NAME" => "glu.ttono.us:8007",
- "FCGI_ROLE" => "RESPONDER",
- "AUTH_TYPE" => "Basic",
- "HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
- "HTTP_ACCEPT_CHARSET" => "UTF-8",
- "HTTP_ACCEPT_ENCODING" => "gzip, deflate",
- "HTTP_CACHE_CONTROL" => "no-cache, max-age=0",
- "HTTP_PRAGMA" => "no-cache",
- "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)",
- "PATH_INFO" => "/homepage/",
- "HTTP_ACCEPT_LANGUAGE" => "en",
- "HTTP_NEGOTIATE" => "trans",
- "HTTP_HOST" => "glu.ttono.us:8007",
- "HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us",
- "HTTP_FROM" => "googlebot",
- "SERVER_PROTOCOL" => "HTTP/1.1",
- "REDIRECT_URI" => "/dispatch.fcgi",
- "SCRIPT_NAME" => "/dispatch.fcgi",
- "SERVER_ADDR" => "207.7.108.53",
- "REMOTE_ADDR" => "207.7.108.53",
- "REMOTE_HOST" => "google.com",
- "REMOTE_IDENT" => "kevin",
- "REMOTE_USER" => "kevin",
- "SERVER_SOFTWARE" => "lighttpd/1.4.5",
- "HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes",
- "HTTP_X_FORWARDED_SERVER" => "glu.ttono.us",
- "REQUEST_URI" => "/admin",
- "DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public",
- "PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/",
- "SERVER_PORT" => "8007",
- "QUERY_STRING" => "",
- "REMOTE_PORT" => "63137",
- "GATEWAY_INTERFACE" => "CGI/1.1",
- "HTTP_X_FORWARDED_FOR" => "65.88.180.234",
- "HTTP_ACCEPT" => "*/*",
- "SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi",
- "REDIRECT_STATUS" => "200",
- "REQUEST_METHOD" => "GET"
- }
- # some Nokia phone browsers omit the space after the semicolon separator.
- # some developers have grown accustomed to using comma in cookie values.
- @alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}
- @cgi = CGI.new
- class << @cgi; attr_accessor :env_table end
- @cgi.env_table = @request_hash
- @request = ActionController::CgiRequest.new(@cgi)
- end
-
- def default_test; end
-
- private
-
- def set_content_data(data)
- @request.env['REQUEST_METHOD'] = 'POST'
- @request.env['CONTENT_LENGTH'] = data.length
- @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
- @request.env['RAW_POST_DATA'] = data
- end
-end
-
-class CgiRequestTest < BaseCgiTest
- def test_proxy_request
- assert_equal 'glu.ttono.us', @request.host_with_port
- end
-
- def test_http_host
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
- @request_hash['HTTP_HOST'] = "rubyonrails.org:8080"
- assert_equal "rubyonrails.org:8080", @request.host_with_port
-
- @request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
- assert_equal "www.secondhost.org", @request.host(true)
- end
-
- def test_http_host_with_default_port_overrides_server_port
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
- @request_hash['HTTP_HOST'] = "rubyonrails.org"
- assert_equal "rubyonrails.org", @request.host_with_port
- end
-
- def test_host_with_port_defaults_to_server_name_if_no_host_headers
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
- @request_hash.delete "HTTP_HOST"
- assert_equal "glu.ttono.us:8007", @request.host_with_port
- end
-
- def test_host_with_port_falls_back_to_server_addr_if_necessary
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
- @request_hash.delete "HTTP_HOST"
- @request_hash.delete "SERVER_NAME"
- assert_equal "207.7.108.53:8007", @request.host_with_port
- end
-
- def test_host_with_port_if_http_standard_port_is_specified
- @request_hash['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
- assert_equal "glu.ttono.us", @request.host_with_port
- end
-
- def test_host_with_port_if_https_standard_port_is_specified
- @request_hash['HTTP_X_FORWARDED_PROTO'] = "https"
- @request_hash['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
- assert_equal "glu.ttono.us", @request.host_with_port
- end
-
- def test_host_if_ipv6_reference
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
- @request_hash['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
- end
-
- def test_host_if_ipv6_reference_with_port
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
- @request_hash['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
- end
-
- def test_cgi_environment_variables
- assert_equal "Basic", @request.auth_type
- assert_equal 0, @request.content_length
- assert_equal nil, @request.content_type
- assert_equal "CGI/1.1", @request.gateway_interface
- assert_equal "*/*", @request.accept
- assert_equal "UTF-8", @request.accept_charset
- assert_equal "gzip, deflate", @request.accept_encoding
- assert_equal "en", @request.accept_language
- assert_equal "no-cache, max-age=0", @request.cache_control
- assert_equal "googlebot", @request.from
- assert_equal "glu.ttono.us", @request.host
- assert_equal "trans", @request.negotiate
- assert_equal "no-cache", @request.pragma
- assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer
- assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent
- assert_equal "/homepage/", @request.path_info
- assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated
- assert_equal "", @request.query_string
- assert_equal "207.7.108.53", @request.remote_addr
- 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 "/dispatch.fcgi", @request.script_name
- assert_equal "glu.ttono.us:8007", @request.server_name
- assert_equal 8007, @request.server_port
- assert_equal "HTTP/1.1", @request.server_protocol
- assert_equal "lighttpd", @request.server_software
- end
-
- def test_cookie_syntax_resilience
- cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]);
- assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
- assert_equal ["yes"], cookies["is_admin"], cookies.inspect
-
- alt_cookies = CGI::Cookie::parse(@alt_cookie_fmt_request_hash["HTTP_COOKIE"]);
- assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect
- assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect
- end
-end
-
-class CgiRequestParamsParsingTest < BaseCgiTest
- def test_doesnt_break_when_content_type_has_charset
- set_content_data 'flamenco=love'
-
- assert_equal({"flamenco"=> "love"}, @request.request_parameters)
- end
-
- def test_doesnt_interpret_request_uri_as_query_string_when_missing
- @request.env['REQUEST_URI'] = 'foo'
- assert_equal({}, @request.query_parameters)
- end
-end
-
-class CgiRequestContentTypeTest < BaseCgiTest
- def test_html_content_type_verification
- @request.env['CONTENT_TYPE'] = Mime::HTML.to_s
- assert @request.content_type.verify_request?
- end
-
- def test_xml_content_type_verification
- @request.env['CONTENT_TYPE'] = Mime::XML.to_s
- assert !@request.content_type.verify_request?
- end
-end
-
-class CgiRequestMethodTest < BaseCgiTest
- def test_get
- assert_equal :get, @request.request_method
- end
-
- def test_post
- @request.env['REQUEST_METHOD'] = 'POST'
- assert_equal :post, @request.request_method
- end
-
- def test_put
- set_content_data '_method=put'
-
- assert_equal :put, @request.request_method
- end
-
- def test_delete
- set_content_data '_method=delete'
-
- assert_equal :delete, @request.request_method
- end
-end
-
-class CgiRequestNeedsRewoundTest < BaseCgiTest
- def test_body_should_be_rewound
- data = 'foo'
- fake_cgi = Struct.new(:env_table, :query_string, :stdinput).new(@request_hash, '', StringIO.new(data))
- fake_cgi.env_table['CONTENT_LENGTH'] = data.length
- fake_cgi.env_table['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
-
- # Read the request body by parsing params.
- request = ActionController::CgiRequest.new(fake_cgi)
- request.request_parameters
-
- # Should have rewound the body.
- assert_equal 0, request.body.pos
- end
-end
-
-uses_mocha 'CGI Response' do
- class CgiResponseTest < BaseCgiTest
- def setup
- super
- @cgi.expects(:header).returns("HTTP/1.0 200 OK\nContent-Type: text/html\n")
- @response = ActionController::CgiResponse.new(@cgi)
- @output = StringIO.new('')
- end
-
- def test_simple_output
- @response.body = "Hello, World!"
-
- @response.out(@output)
- assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\nHello, World!", @output.string
- end
-
- def test_head_request
- @cgi.env_table['REQUEST_METHOD'] = 'HEAD'
- @response.body = "Hello, World!"
-
- @response.out(@output)
- assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n", @output.string
- end
-
- def test_streaming_block
- @response.body = Proc.new do |response, output|
- 5.times { |n| output.write(n) }
- end
-
- @response.out(@output)
- assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n01234", @output.string
- end
- end
-end
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index 61bfb2b6e9..30dda87bb4 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -6,7 +6,6 @@ class DispatcherTest < Test::Unit::TestCase
Dispatcher = ActionController::Dispatcher
def setup
- @output = StringIO.new
ENV['REQUEST_METHOD'] = 'GET'
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
@@ -16,7 +15,7 @@ class DispatcherTest < Test::Unit::TestCase
Dispatcher.stubs(:require_dependency)
- @dispatcher = Dispatcher.new(@output)
+ @dispatcher = Dispatcher.new
end
def teardown
@@ -25,17 +24,17 @@ class DispatcherTest < Test::Unit::TestCase
def test_clears_dependencies_after_dispatch_if_in_loading_mode
ActiveSupport::Dependencies.expects(:clear).once
- dispatch(@output, false)
+ dispatch(false)
end
def test_reloads_routes_before_dispatch_if_in_loading_mode
ActionController::Routing::Routes.expects(:reload).once
- dispatch(@output, false)
+ dispatch(false)
end
def test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode
ActionView::Helpers::AssetTagHelper::AssetTag::Cache.expects(:clear).once
- dispatch(@output, false)
+ dispatch(false)
end
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
@@ -51,12 +50,16 @@ class DispatcherTest < Test::Unit::TestCase
end
def test_failsafe_response
- CGI.expects(:new).raises('some multipart parsing failure')
- Dispatcher.expects(:log_failsafe_exception)
-
- assert_nothing_raised { dispatch }
-
- assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n<html><body><h1>400 Bad Request</h1></body></html>", @output.string
+ Dispatcher.any_instance.expects(:dispatch_unlocked).raises('b00m')
+ ActionController::Failsafe.any_instance.expects(:log_failsafe_exception)
+
+ assert_nothing_raised do
+ assert_equal [
+ 500,
+ {"Content-Type" => "text/html"},
+ "<html><body><h1>500 Internal Server Error</h1></body></html>"
+ ], dispatch
+ end
end
def test_prepare_callbacks
@@ -77,7 +80,7 @@ class DispatcherTest < Test::Unit::TestCase
# Make sure they are only run once
a = b = c = nil
- @dispatcher.send :dispatch
+ dispatch
assert_nil a || b || c
end
@@ -92,15 +95,10 @@ class DispatcherTest < Test::Unit::TestCase
end
private
- def dispatch(output = @output, cache_classes = true)
- controller = mock
- controller.stubs(:process).returns(controller)
- controller.stubs(:out).with(output).returns('response')
-
- ActionController::Routing::Routes.stubs(:recognize).returns(controller)
-
+ def dispatch(cache_classes = true)
+ Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response'])
Dispatcher.define_dispatcher_callbacks(cache_classes)
- Dispatcher.dispatch(nil, {}, output)
+ @dispatcher.call({})
end
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index b39d35930d..4735b2927b 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -2,19 +2,13 @@ require 'abstract_unit'
uses_mocha 'integration' do
-module IntegrationSessionStubbing
- def stub_integration_session(session)
- session.stubs(:process)
- session.stubs(:generic_url_rewriter)
- end
-end
-
class SessionTest < Test::Unit::TestCase
- include IntegrationSessionStubbing
+ StubApp = lambda { |env|
+ [200, {"Content-Type" => "text/html"}, "Hello, World!"]
+ }
def setup
- @session = ActionController::Integration::Session.new
- stub_integration_session(@session)
+ @session = ActionController::Integration::Session.new(StubApp)
end
def test_https_bang_works_and_sets_truth_by_default
@@ -207,13 +201,10 @@ class SessionTest < Test::Unit::TestCase
end
class IntegrationTestTest < Test::Unit::TestCase
- include IntegrationSessionStubbing
-
def setup
@test = ::ActionController::IntegrationTest.new(:default_test)
@test.class.stubs(:fixture_table_names).returns([])
@session = @test.open_session
- stub_integration_session(@session)
end
def test_opens_new_session
@@ -231,15 +222,15 @@ end
# Tests that integration tests don't call Controller test methods for processing.
# Integration tests have their own setup and teardown.
class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
- include IntegrationSessionStubbing
-
def self.fixture_table_names
[]
end
def test_integration_methods_called
reset!
- stub_integration_session(@integration_session)
+ @integration_session.stubs(:generic_url_rewriter)
+ @integration_session.stubs(:process)
+
%w( get post head put delete ).each do |verb|
assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') }
end
@@ -281,13 +272,9 @@ class IntegrationProcessTest < ActionController::IntegrationTest
get '/get'
assert_equal 200, status
assert_equal "OK", status_message
- assert_equal "200 OK", response.headers["Status"]
- assert_equal ["200 OK"], headers["status"]
assert_response 200
assert_response :success
assert_response :ok
- assert_equal [], response.headers["cookie"]
- assert_equal [], headers["cookie"]
assert_equal({}, cookies)
assert_equal "OK", response.body
assert_kind_of HTML::Document, html_document
@@ -300,13 +287,9 @@ class IntegrationProcessTest < ActionController::IntegrationTest
post '/post'
assert_equal 201, status
assert_equal "Created", status_message
- assert_equal "201 Created", response.headers["Status"]
- assert_equal ["201 Created"], headers["status"]
assert_response 201
assert_response :success
assert_response :created
- assert_equal [], response.headers["cookie"]
- assert_equal [], headers["cookie"]
assert_equal({}, cookies)
assert_equal "Created", response.body
assert_kind_of HTML::Document, html_document
@@ -321,17 +304,9 @@ class IntegrationProcessTest < ActionController::IntegrationTest
get '/cookie_monster'
assert_equal 410, status
assert_equal "Gone", status_message
- assert_equal "410 Gone", response.headers["Status"]
- assert_equal ["410 Gone"], headers["status"]
assert_response 410
assert_response :gone
- assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], response.headers["Set-Cookie"]
- assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers['set-cookie']
- assert_equal [
- CGI::Cookie::new("name" => "cookie_1", "value" => ""),
- CGI::Cookie::new("name" => "cookie_3", "value" => "chocolate")
- ], response.headers["cookie"]
- assert_equal [], headers["cookie"]
+ assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers["Set-Cookie"]
assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
assert_equal "Gone", response.body
end
@@ -342,8 +317,6 @@ class IntegrationProcessTest < ActionController::IntegrationTest
get '/redirect'
assert_equal 302, status
assert_equal "Found", status_message
- assert_equal "302 Found", response.headers["Status"]
- assert_equal ["302 Found"], headers["status"]
assert_response 302
assert_response :redirect
assert_response :found
@@ -358,8 +331,6 @@ class IntegrationProcessTest < ActionController::IntegrationTest
xhr :get, '/get'
assert_equal 200, status
assert_equal "OK", status_message
- assert_equal "200 OK", response.headers["Status"]
- assert_equal ["200 OK"], headers["status"]
assert_response 200
assert_response :success
assert_response :ok
@@ -372,7 +343,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
get '/get_with_params?foo=bar'
assert_equal '/get_with_params?foo=bar', request.env["REQUEST_URI"]
assert_equal '/get_with_params?foo=bar', request.request_uri
- assert_equal nil, request.env["QUERY_STRING"]
+ assert_equal "", request.env["QUERY_STRING"]
assert_equal 'foo=bar', request.query_string
assert_equal 'bar', request.parameters['foo']
diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb
index 7e8b0f9bf2..641ef9626e 100644
--- a/actionpack/test/controller/rack_test.rb
+++ b/actionpack/test/controller/rack_test.rb
@@ -153,12 +153,12 @@ class RackRequestTest < BaseRackTest
def test_cookie_syntax_resilience
cookies = @request.cookies
- assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
- assert_equal ["yes"], cookies["is_admin"], cookies.inspect
+ assert_equal "c84ace84796670c052c6ceb2451fb0f2", cookies["_session_id"], cookies.inspect
+ assert_equal "yes", cookies["is_admin"], cookies.inspect
alt_cookies = @alt_cookie_fmt_request.cookies
- assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect
- assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect
+ #assert_equal "c84ace847,96670c052c6ceb2451fb0f2", alt_cookies["_session_id"], alt_cookies.inspect
+ assert_equal "yes", alt_cookies["is_admin"], alt_cookies.inspect
end
end
@@ -230,14 +230,13 @@ class RackResponseTest < BaseRackTest
def setup
super
@response = ActionController::RackResponse.new(@request)
- @output = StringIO.new('')
end
def test_simple_output
@response.body = "Hello, World!"
@response.prepare!
- status, headers, body = @response.out(@output)
+ status, headers, body = @response.out
assert_equal "200 OK", status
assert_equal({
"Content-Type" => "text/html; charset=utf-8",
@@ -258,7 +257,7 @@ class RackResponseTest < BaseRackTest
end
@response.prepare!
- status, headers, body = @response.out(@output)
+ status, headers, body = @response.out
assert_equal "200 OK", status
assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
@@ -274,7 +273,7 @@ class RackResponseTest < BaseRackTest
@response.body = "Hello, World!"
@response.prepare!
- status, headers, body = @response.out(@output)
+ status, headers, body = @response.out
assert_equal "200 OK", status
assert_equal({
"Content-Type" => "text/html; charset=utf-8",
@@ -294,7 +293,6 @@ class RackResponseHeadersTest < BaseRackTest
def setup
super
@response = ActionController::RackResponse.new(@request)
- @output = StringIO.new('')
@response.headers['Status'] = "200 OK"
end
@@ -317,6 +315,6 @@ class RackResponseHeadersTest < BaseRackTest
private
def response_headers
@response.prepare!
- @response.out(@output)[1]
+ @response.out[1]
end
end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 972e425e35..c5496a9af5 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -246,13 +246,10 @@ class TestController < ActionController::Base
:locals => { :local_name => name }
end
- def helper_method_to_render_to_string(*args)
- render_to_string(*args)
+ def render_implicit_html_template
end
- helper_method :helper_method_to_render_to_string
- def render_html_only_partial_within_inline
- render :inline => "Hello world <%= helper_method_to_render_to_string :partial => 'test/partial_with_only_html_version' %>"
+ def render_explicit_html_template
end
def formatted_html_erb
@@ -942,9 +939,22 @@ class RenderTest < ActionController::TestCase
assert_equal "Goodbye, Local David", @response.body
end
- def test_rendering_html_only_partial_within_inline_with_js
- get :render_html_only_partial_within_inline, :format => :js
- assert_equal "Hello world partial with only html version", @response.body
+ def test_render_in_an_rjs_template_should_pick_html_templates_when_available
+ [:js, "js"].each do |format|
+ assert_nothing_raised do
+ get :render_implicit_html_template, :format => format
+ assert_equal %(document.write("Hello world\\n");), @response.body
+ end
+ end
+ end
+
+ def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template
+ [:js, "js"].each do |format|
+ assert_nothing_raised do
+ get :render_explicit_html_template, :format => format
+ assert_equal %(document.write("Hello world\\n");), @response.body
+ end
+ end
end
def test_should_render_formatted_template
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index ba4a6da39b..71da50fab0 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -637,7 +637,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase
input = {
"customers[boston][first][name]" => [ "David" ],
"something_else" => [ "blah" ],
- "logo" => [ File.new(File.dirname(__FILE__) + "/cgi_test.rb").path ]
+ "logo" => [ File.new(File.dirname(__FILE__) + "/rack_test.rb").path ]
}
expected_output = {
@@ -649,7 +649,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase
}
},
"something_else" => "blah",
- "logo" => File.new(File.dirname(__FILE__) + "/cgi_test.rb").path,
+ "logo" => File.new(File.dirname(__FILE__) + "/rack_test.rb").path,
}
assert_equal expected_output, ActionController::AbstractRequest.parse_request_parameters(input)
diff --git a/actionpack/test/controller/session_fixation_test.rb b/actionpack/test/controller/session_fixation_test.rb
index 164438c513..e8dc8bd295 100644
--- a/actionpack/test/controller/session_fixation_test.rb
+++ b/actionpack/test/controller/session_fixation_test.rb
@@ -1,20 +1,13 @@
require 'abstract_unit'
-
-class SessionFixationTest < Test::Unit::TestCase
- class MockCGI < CGI #:nodoc:
- attr_accessor :stdoutput, :env_table
-
- def initialize(env, data = '')
- self.env_table = env
- self.stdoutput = StringIO.new
- super(nil, StringIO.new(data))
- end
- end
-
+class SessionFixationTest < ActionController::IntegrationTest
class TestController < ActionController::Base
- session :session_key => '_myapp_session_id', :secret => CGI::Session.generate_unique_id, :except => :default_session_key
- session :cookie_only => false, :only => :allow_session_fixation
+ session :session_key => '_myapp_session_id',
+ :secret => CGI::Session.generate_unique_id,
+ :except => :default_session_key
+
+ session :cookie_only => false,
+ :only => :allow_session_fixation
def default_session_key
render :text => "default_session_key"
@@ -36,54 +29,56 @@ class SessionFixationTest < Test::Unit::TestCase
end
def test_should_be_able_to_make_a_successful_request
- cgi = mock_cgi_for_request_to(:custom_session_key, :id => 1)
-
- assert_nothing_raised do
- @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
+ with_test_route_set do
+ assert_nothing_raised do
+ get '/custom_session_key', :id => "1"
+ end
+ assert_equal 'custom_session_key: 1', @controller.response.body
+ assert_not_nil @controller.session
end
- assert_equal 'custom_session_key: 1', @controller.response.body
- assert_not_nil @controller.session
end
def test_should_catch_session_fixation_attempt
- cgi = mock_cgi_for_request_to(:custom_session_key, :_myapp_session_id => 42)
-
- assert_raises ActionController::CgiRequest::SessionFixationAttempt do
- @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
+ with_test_route_set do
+ assert_raises(ActionController::RackRequest::SessionFixationAttempt) do
+ get '/custom_session_key', :_myapp_session_id => "42"
+ end
+ assert_nil @controller.session
end
- assert_nil @controller.session
end
def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled
- cgi = mock_cgi_for_request_to(:allow_session_fixation, :_myapp_session_id => 42)
-
- assert_nothing_raised do
- @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
+ with_test_route_set do
+ assert_nothing_raised do
+ get '/allow_session_fixation', :_myapp_session_id => "42"
+ end
+ assert !@controller.response.body.blank?
+ assert_not_nil @controller.session
end
- assert ! @controller.response.body.blank?
- assert_not_nil @controller.session
end
def test_should_catch_session_fixation_attempt_with_default_session_key
- ActionController::Base.session_store = :p_store # using the default session_key is not possible with cookie store
- cgi = mock_cgi_for_request_to(:default_session_key, :_session_id => 42)
-
- assert_raises ActionController::CgiRequest::SessionFixationAttempt do
- @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
+ # using the default session_key is not possible with cookie store
+ ActionController::Base.session_store = :p_store
+
+ with_test_route_set do
+ assert_raises ActionController::RackRequest::SessionFixationAttempt do
+ get '/default_session_key', :_session_id => "42"
+ end
+ assert_nil @controller.response
+ assert_nil @controller.session
end
- assert @controller.response.body.blank?
- assert_nil @controller.session
- end
-
-private
-
- def mock_cgi_for_request_to(action, params = {})
- MockCGI.new({
- "REQUEST_METHOD" => "GET",
- "QUERY_STRING" => "action=#{action}&#{params.to_query}",
- "REQUEST_URI" => "/",
- "SERVER_PORT" => "80",
- "HTTP_HOST" => "testdomain.com" }, '')
end
+ private
+ def with_test_route_set
+ with_routing do |set|
+ set.draw do |map|
+ map.with_options :controller => "session_fixation_test/test" do |c|
+ c.connect "/:action"
+ end
+ end
+ yield
+ end
+ end
end
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 04e14d8eac..ac84e2dfcd 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -43,29 +43,29 @@ class ViewLoadPathsTest < ActionController::TestCase
end
def test_template_load_path_was_set_correctly
- assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
end
def test_controller_appends_view_path_correctly
@controller.append_view_path 'foo'
- assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s)
@controller.append_view_path(%w(bar baz))
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s)
@controller.append_view_path(FIXTURE_LOAD_PATH)
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
end
def test_controller_prepends_view_path_correctly
@controller.prepend_view_path 'baz'
- assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
@controller.prepend_view_path(%w(foo bar))
- assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
@controller.prepend_view_path(FIXTURE_LOAD_PATH)
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
end
def test_template_appends_view_path_correctly
@@ -73,10 +73,10 @@ class ViewLoadPathsTest < ActionController::TestCase
class_view_paths = TestController.view_paths
@controller.append_view_path 'foo'
- assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s)
@controller.append_view_path(%w(bar baz))
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s)
assert_equal class_view_paths, TestController.view_paths
end
@@ -85,10 +85,10 @@ class ViewLoadPathsTest < ActionController::TestCase
class_view_paths = TestController.view_paths
@controller.prepend_view_path 'baz'
- assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
@controller.prepend_view_path(%w(foo bar))
- assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
+ assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
assert_equal class_view_paths, TestController.view_paths
end
@@ -130,12 +130,12 @@ class ViewLoadPathsTest < ActionController::TestCase
A.view_paths = ['a/path']
- assert_equal ['a/path'], A.view_paths
+ assert_equal ['a/path'], A.view_paths.map(&:to_s)
assert_equal A.view_paths, B.view_paths
assert_equal original_load_paths, C.view_paths
C.view_paths = []
assert_nothing_raised { C.view_paths << 'c/path' }
- assert_equal ['c/path'], C.view_paths
+ assert_equal ['c/path'], C.view_paths.map(&:to_s)
end
end
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb
index 6d2b3e4f23..4c44ea4205 100644
--- a/actionpack/test/controller/webservice_test.rb
+++ b/actionpack/test/controller/webservice_test.rb
@@ -1,16 +1,6 @@
require 'abstract_unit'
-class WebServiceTest < Test::Unit::TestCase
- class MockCGI < CGI #:nodoc:
- attr_accessor :stdoutput, :env_table
-
- def initialize(env, data = '')
- self.env_table = env
- self.stdoutput = StringIO.new
- super(nil, StringIO.new(data))
- end
- end
-
+class WebServiceTest < ActionController::IntegrationTest
class TestController < ActionController::Base
session :off
@@ -22,7 +12,7 @@ class WebServiceTest < Test::Unit::TestCase
end
end
- def dump_params_keys(hash=params)
+ def dump_params_keys(hash = params)
hash.keys.sort.inject("") do |s, k|
value = hash[k]
value = Hash === value ? "(#{dump_params_keys(value)})" : ""
@@ -33,7 +23,7 @@ class WebServiceTest < Test::Unit::TestCase
def rescue_action(e) raise end
end
-
+
def setup
@controller = TestController.new
@default_param_parsers = ActionController::Base.param_parsers.dup
@@ -44,185 +34,229 @@ class WebServiceTest < Test::Unit::TestCase
end
def test_check_parameters
- process('GET')
- assert_equal '', @controller.response.body
+ with_test_route_set do
+ get "/"
+ assert_equal '', @controller.response.body
+ end
end
def test_post_xml
- process('POST', 'application/xml', '<entry attributed="true"><summary>content...</summary></entry>')
-
- assert_equal 'entry', @controller.response.body
- assert @controller.params.has_key?(:entry)
- assert_equal 'content...', @controller.params["entry"]['summary']
- assert_equal 'true', @controller.params["entry"]['attributed']
+ with_test_route_set do
+ post "/", '<entry attributed="true"><summary>content...</summary></entry>',
+ {'CONTENT_TYPE' => 'application/xml'}
+
+ assert_equal 'entry', @controller.response.body
+ assert @controller.params.has_key?(:entry)
+ assert_equal 'content...', @controller.params["entry"]['summary']
+ assert_equal 'true', @controller.params["entry"]['attributed']
+ end
end
def test_put_xml
- process('PUT', 'application/xml', '<entry attributed="true"><summary>content...</summary></entry>')
+ with_test_route_set do
+ put "/", '<entry attributed="true"><summary>content...</summary></entry>',
+ {'CONTENT_TYPE' => 'application/xml'}
- assert_equal 'entry', @controller.response.body
- assert @controller.params.has_key?(:entry)
- assert_equal 'content...', @controller.params["entry"]['summary']
- assert_equal 'true', @controller.params["entry"]['attributed']
+ assert_equal 'entry', @controller.response.body
+ assert @controller.params.has_key?(:entry)
+ assert_equal 'content...', @controller.params["entry"]['summary']
+ assert_equal 'true', @controller.params["entry"]['attributed']
+ end
end
def test_put_xml_using_a_type_node
- process('PUT', 'application/xml', '<type attributed="true"><summary>content...</summary></type>')
+ with_test_route_set do
+ put "/", '<type attributed="true"><summary>content...</summary></type>',
+ {'CONTENT_TYPE' => 'application/xml'}
- assert_equal 'type', @controller.response.body
- assert @controller.params.has_key?(:type)
- assert_equal 'content...', @controller.params["type"]['summary']
- assert_equal 'true', @controller.params["type"]['attributed']
+ assert_equal 'type', @controller.response.body
+ assert @controller.params.has_key?(:type)
+ assert_equal 'content...', @controller.params["type"]['summary']
+ assert_equal 'true', @controller.params["type"]['attributed']
+ end
end
def test_put_xml_using_a_type_node_and_attribute
- process('PUT', 'application/xml', '<type attributed="true"><summary type="boolean">false</summary></type>')
+ with_test_route_set do
+ put "/", '<type attributed="true"><summary type="boolean">false</summary></type>',
+ {'CONTENT_TYPE' => 'application/xml'}
- assert_equal 'type', @controller.response.body
- assert @controller.params.has_key?(:type)
- assert_equal false, @controller.params["type"]['summary']
- assert_equal 'true', @controller.params["type"]['attributed']
+ assert_equal 'type', @controller.response.body
+ assert @controller.params.has_key?(:type)
+ assert_equal false, @controller.params["type"]['summary']
+ assert_equal 'true', @controller.params["type"]['attributed']
+ end
end
def test_post_xml_using_a_type_node
- process('POST', 'application/xml', '<font attributed="true"><type>arial</type></font>')
+ with_test_route_set do
+ post "/", '<font attributed="true"><type>arial</type></font>',
+ {'CONTENT_TYPE' => 'application/xml'}
- assert_equal 'font', @controller.response.body
- assert @controller.params.has_key?(:font)
- assert_equal 'arial', @controller.params['font']['type']
- assert_equal 'true', @controller.params["font"]['attributed']
+ assert_equal 'font', @controller.response.body
+ assert @controller.params.has_key?(:font)
+ assert_equal 'arial', @controller.params['font']['type']
+ assert_equal 'true', @controller.params["font"]['attributed']
+ end
end
def test_post_xml_using_a_root_node_named_type
- process('POST', 'application/xml', '<type type="integer">33</type>')
+ with_test_route_set do
+ post "/", '<type type="integer">33</type>',
+ {'CONTENT_TYPE' => 'application/xml'}
- assert @controller.params.has_key?(:type)
- assert_equal 33, @controller.params['type']
+ assert @controller.params.has_key?(:type)
+ assert_equal 33, @controller.params['type']
+ end
end
def test_post_xml_using_an_attributted_node_named_type
- ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
- process('POST', 'application/xml', '<request><type type="string">Arial,12</type><z>3</z></request>')
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
+ post "/", '<request><type type="string">Arial,12</type><z>3</z></request>',
+ {'CONTENT_TYPE' => 'application/xml'}
- assert_equal 'type, z', @controller.response.body
- assert @controller.params.has_key?(:type)
- assert_equal 'Arial,12', @controller.params['type'], @controller.params.inspect
- assert_equal '3', @controller.params['z'], @controller.params.inspect
+ assert_equal 'type, z', @controller.response.body
+ assert @controller.params.has_key?(:type)
+ assert_equal 'Arial,12', @controller.params['type'], @controller.params.inspect
+ assert_equal '3', @controller.params['z'], @controller.params.inspect
+ end
end
def test_register_and_use_yaml
- ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) }
- process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml)
- assert_equal 'entry', @controller.response.body
- assert @controller.params.has_key?(:entry)
- assert_equal 'loaded from yaml', @controller.params["entry"]
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) }
+ post "/", {"entry" => "loaded from yaml"}.to_yaml,
+ {'CONTENT_TYPE' => 'application/x-yaml'}
+
+ assert_equal 'entry', @controller.response.body
+ assert @controller.params.has_key?(:entry)
+ assert_equal 'loaded from yaml', @controller.params["entry"]
+ end
end
-
+
def test_register_and_use_yaml_as_symbol
- ActionController::Base.param_parsers[Mime::YAML] = :yaml
- process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml)
- assert_equal 'entry', @controller.response.body
- assert @controller.params.has_key?(:entry)
- assert_equal 'loaded from yaml', @controller.params["entry"]
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::YAML] = :yaml
+ post "/", {"entry" => "loaded from yaml"}.to_yaml,
+ {'CONTENT_TYPE' => 'application/x-yaml'}
+
+ assert_equal 'entry', @controller.response.body
+ assert @controller.params.has_key?(:entry)
+ assert_equal 'loaded from yaml', @controller.params["entry"]
+ end
end
def test_register_and_use_xml_simple
- ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
- process('POST', 'application/xml', '<request><summary>content...</summary><title>SimpleXml</title></request>' )
- assert_equal 'summary, title', @controller.response.body
- assert @controller.params.has_key?(:summary)
- assert @controller.params.has_key?(:title)
- assert_equal 'content...', @controller.params["summary"]
- assert_equal 'SimpleXml', @controller.params["title"]
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
+ post "/", '<request><summary>content...</summary><title>SimpleXml</title></request>',
+ {'CONTENT_TYPE' => 'application/xml'}
+
+ assert_equal 'summary, title', @controller.response.body
+ assert @controller.params.has_key?(:summary)
+ assert @controller.params.has_key?(:title)
+ assert_equal 'content...', @controller.params["summary"]
+ assert_equal 'SimpleXml', @controller.params["title"]
+ end
end
def test_use_xml_ximple_with_empty_request
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
- assert_nothing_raised { process('POST', 'application/xml', "") }
- assert_equal "", @controller.response.body
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
+ assert_nothing_raised { post "/", "", {'CONTENT_TYPE' => 'application/xml'} }
+ assert_equal "", @controller.response.body
+ end
end
def test_dasherized_keys_as_xml
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
- process('POST', 'application/xml', "<first-key>\n<sub-key>...</sub-key>\n</first-key>", true)
- assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body
- assert_equal "...", @controller.params[:first_key][:sub_key]
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
+ post "/?full=1", "<first-key>\n<sub-key>...</sub-key>\n</first-key>",
+ {'CONTENT_TYPE' => 'application/xml'}
+ assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body
+ assert_equal "...", @controller.params[:first_key][:sub_key]
+ end
end
def test_typecast_as_xml
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
- process('POST', 'application/xml', <<-XML)
- <data>
- <a type="integer">15</a>
- <b type="boolean">false</b>
- <c type="boolean">true</c>
- <d type="date">2005-03-17</d>
- <e type="datetime">2005-03-17T21:41:07Z</e>
- <f>unparsed</f>
- <g type="integer">1</g>
- <g>hello</g>
- <g type="date">1974-07-25</g>
- </data>
- XML
- params = @controller.params
- assert_equal 15, params[:data][:a]
- assert_equal false, params[:data][:b]
- assert_equal true, params[:data][:c]
- assert_equal Date.new(2005,3,17), params[:data][:d]
- assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
- assert_equal "unparsed", params[:data][:f]
- assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
+ xml = <<-XML
+ <data>
+ <a type="integer">15</a>
+ <b type="boolean">false</b>
+ <c type="boolean">true</c>
+ <d type="date">2005-03-17</d>
+ <e type="datetime">2005-03-17T21:41:07Z</e>
+ <f>unparsed</f>
+ <g type="integer">1</g>
+ <g>hello</g>
+ <g type="date">1974-07-25</g>
+ </data>
+ XML
+ post "/", xml, {'CONTENT_TYPE' => 'application/xml'}
+
+ params = @controller.params
+ assert_equal 15, params[:data][:a]
+ assert_equal false, params[:data][:b]
+ assert_equal true, params[:data][:c]
+ assert_equal Date.new(2005,3,17), params[:data][:d]
+ assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
+ assert_equal "unparsed", params[:data][:f]
+ assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
+ end
end
def test_entities_unescaped_as_xml_simple
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
- process('POST', 'application/xml', <<-XML)
- <data>&lt;foo &quot;bar&apos;s&quot; &amp; friends&gt;</data>
- XML
- assert_equal %(<foo "bar's" & friends>), @controller.params[:data]
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
+ xml = <<-XML
+ <data>&lt;foo &quot;bar&apos;s&quot; &amp; friends&gt;</data>
+ XML
+ post "/", xml, {'CONTENT_TYPE' => 'application/xml'}
+ assert_equal %(<foo "bar's" & friends>), @controller.params[:data]
+ end
end
def test_typecast_as_yaml
- ActionController::Base.param_parsers[Mime::YAML] = :yaml
- process('POST', 'application/x-yaml', <<-YAML)
- ---
- data:
- a: 15
- b: false
- c: true
- d: 2005-03-17
- e: 2005-03-17T21:41:07Z
- f: unparsed
- g:
- - 1
- - hello
- - 1974-07-25
- YAML
- params = @controller.params
- assert_equal 15, params[:data][:a]
- assert_equal false, params[:data][:b]
- assert_equal true, params[:data][:c]
- assert_equal Date.new(2005,3,17), params[:data][:d]
- assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
- assert_equal "unparsed", params[:data][:f]
- assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
- end
-
- private
-
- def process(verb, content_type = 'application/x-www-form-urlencoded', data = '', full=false)
-
- cgi = MockCGI.new({
- 'REQUEST_METHOD' => verb,
- 'CONTENT_TYPE' => content_type,
- 'QUERY_STRING' => "action=assign_parameters&controller=webservicetest/test#{"&full=1" if full}",
- "REQUEST_URI" => "/",
- "HTTP_HOST" => 'testdomain.com',
- "CONTENT_LENGTH" => data.size,
- "SERVER_PORT" => "80",
- "HTTPS" => "off"}, data)
-
- @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
- end
-
+ with_test_route_set do
+ ActionController::Base.param_parsers[Mime::YAML] = :yaml
+ yaml = <<-YAML
+ ---
+ data:
+ a: 15
+ b: false
+ c: true
+ d: 2005-03-17
+ e: 2005-03-17T21:41:07Z
+ f: unparsed
+ g:
+ - 1
+ - hello
+ - 1974-07-25
+ YAML
+ post "/", yaml, {'CONTENT_TYPE' => 'application/x-yaml'}
+ params = @controller.params
+ assert_equal 15, params[:data][:a]
+ assert_equal false, params[:data][:b]
+ assert_equal true, params[:data][:c]
+ assert_equal Date.new(2005,3,17), params[:data][:d]
+ assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
+ assert_equal "unparsed", params[:data][:f]
+ assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
+ end
+ end
+
+ private
+ def with_test_route_set
+ with_routing do |set|
+ set.draw do |map|
+ map.with_options :controller => "web_service_test/test" do |c|
+ c.connect "/", :action => "assign_parameters"
+ end
+ end
+ yield
+ end
+ end
end