Permalink
Browse files

Move dispatch related tests into test/dispatch

  • Loading branch information...
1 parent 319ae46 commit 85750f22c90c914a429116fb908990c5a2c68379 @josh josh committed Jan 29, 2009
View
@@ -30,7 +30,7 @@ Rake::TestTask.new(:test_action_pack) do |t|
# make sure we include the tests in alphabetical order as on some systems
# this will not happen automatically and the tests (as a whole) will error
- t.test_files = Dir.glob( "test/[cft]*/**/*_test.rb" ).sort
+ t.test_files = Dir.glob( "test/[cdft]*/**/*_test.rb" ).sort
t.verbose = true
#t.warning = true
@@ -1,14 +0,0 @@
-require 'abstract_unit'
-
-class HeaderTest < Test::Unit::TestCase
- def setup
- @headers = ActionDispatch::Http::Headers.new("HTTP_CONTENT_TYPE"=>"text/plain")
- end
-
- def test_content_type_works
- assert_equal "text/plain", @headers["Content-Type"]
- assert_equal "text/plain", @headers["content-type"]
- assert_equal "text/plain", @headers["CONTENT_TYPE"]
- assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
- end
-end
@@ -0,0 +1,16 @@
+require 'abstract_unit'
+
+class HeaderTest < ActiveSupport::TestCase
+ def setup
+ @headers = ActionDispatch::Http::Headers.new(
+ "HTTP_CONTENT_TYPE" => "text/plain"
+ )
+ end
+
+ test "content type" do
+ assert_equal "text/plain", @headers["Content-Type"]
+ assert_equal "text/plain", @headers["content-type"]
+ assert_equal "text/plain", @headers["CONTENT_TYPE"]
+ assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
+ end
+end
@@ -1,57 +1,60 @@
require 'abstract_unit'
-class MimeTypeTest < Test::Unit::TestCase
- Mime::Type.register "image/png", :png
- Mime::Type.register "application/pdf", :pdf
+class MimeTypeTest < ActiveSupport::TestCase
+ Mime::Type.register "image/png", :png unless defined? Mime::PNG
+ Mime::Type.register "application/pdf", :pdf unless defined? Mime::PDF
- def test_parse_single
+ test "parse single" do
Mime::LOOKUP.keys.each do |mime_type|
assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type)
end
end
- def test_parse_without_q
+ test "parse without q" do
accept = "text/xml,application/xhtml+xml,text/yaml,application/xml,text/html,image/png,text/plain,application/pdf,*/*"
expect = [Mime::HTML, Mime::XML, Mime::YAML, Mime::PNG, Mime::TEXT, Mime::PDF, Mime::ALL]
assert_equal expect, Mime::Type.parse(accept)
end
- def test_parse_with_q
+ test "parse with q" do
accept = "text/xml,application/xhtml+xml,text/yaml; q=0.3,application/xml,text/html; q=0.8,image/png,text/plain; q=0.5,application/pdf,*/*; q=0.2"
expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PDF, Mime::TEXT, Mime::YAML, Mime::ALL]
assert_equal expect, Mime::Type.parse(accept)
end
-
+
# Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP)
- def test_parse_crappy_broken_acceptlines
+ test "parse crappy broken acceptlines" do
accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5"
expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
end
- # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
- def test_parse_crappy_broken_acceptlines2
+ # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0
+ # (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
+ test "parse crappy broken acceptlines2" do
accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
end
-
- def test_custom_type
- Mime::Type.register("image/gif", :gif)
- assert_nothing_raised do
- Mime::GIF
- assert_equal Mime::GIF, Mime::SET.last
+
+ test "custom type" do
+ begin
+ Mime::Type.register("image/gif", :gif)
+ assert_nothing_raised do
+ Mime::GIF
+ assert_equal Mime::GIF, Mime::SET.last
+ end
+ ensure
+ Mime.module_eval { remove_const :GIF if const_defined?(:GIF) }
end
- ensure
- Mime.module_eval { remove_const :GIF if const_defined?(:GIF) }
end
-
- def test_type_should_be_equal_to_symbol
+
+ test "type should be equal to symbol" do
assert_equal Mime::HTML, 'application/xhtml+xml'
assert_equal Mime::HTML, :html
end
- def test_type_convenience_methods
+ test "type convenience methods" do
# Don't test Mime::ALL, since it Mime::ALL#html? == true
types = Mime::SET.to_a.map(&:to_sym).uniq - [:all]
@@ -67,12 +70,12 @@ def test_type_convenience_methods
end
end
- def test_mime_all_is_html
+ test "mime all is html" do
assert Mime::ALL.all?, "Mime::ALL is not all?"
assert Mime::ALL.html?, "Mime::ALL is not html?"
end
- def test_verifiable_mime_types
+ test "verifiable mime types" do
all_types = Mime::SET.to_a.map(&:to_sym)
all_types.uniq!
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
@@ -82,7 +85,7 @@ def test_verifiable_mime_types
assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
end
- def test_regexp_matcher
+ test "regexp matcher" do
assert Mime::JS =~ "text/javascript"
assert Mime::JS =~ "application/javascript"
assert Mime::JS !~ "text/html"
@@ -1,6 +1,8 @@
require 'abstract_unit'
-class BaseRackTest < Test::Unit::TestCase
+# TODO: Merge these tests into RequestTest
+
+class BaseRackTest < ActiveSupport::TestCase
def setup
@env = {
"HTTP_MAX_FORWARDS" => "10",
@@ -49,24 +51,21 @@ def setup
@alt_cookie_fmt_request = ActionDispatch::Request.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}))
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['rack.input'] = StringIO.new(data)
- end
+ 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['rack.input'] = StringIO.new(data)
+ end
end
class RackRequestTest < BaseRackTest
- def test_proxy_request
+ test "proxy request" do
assert_equal 'glu.ttono.us', @request.host_with_port(true)
end
- def test_http_host
+ test "http host" do
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "rubyonrails.org:8080"
assert_equal "rubyonrails.org", @request.host(true)
@@ -76,19 +75,19 @@ def test_http_host
assert_equal "www.secondhost.org", @request.host(true)
end
- def test_http_host_with_default_port_overrides_server_port
+ test "http host with default port overrides server port" do
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "rubyonrails.org"
assert_equal "rubyonrails.org", @request.host_with_port(true)
end
- def test_host_with_port_defaults_to_server_name_if_no_host_headers
+ test "host with port defaults to server name if no host headers" do
@env.delete "HTTP_X_FORWARDED_HOST"
@env.delete "HTTP_HOST"
assert_equal "glu.ttono.us:8007", @request.host_with_port(true)
end
- def test_host_with_port_falls_back_to_server_addr_if_necessary
+ test "host with port falls back to server addr if necessary" do
@env.delete "HTTP_X_FORWARDED_HOST"
@env.delete "HTTP_HOST"
@env.delete "SERVER_NAME"
@@ -97,30 +96,30 @@ def test_host_with_port_falls_back_to_server_addr_if_necessary
assert_equal "207.7.108.53:8007", @request.host_with_port(true)
end
- def test_host_with_port_if_http_standard_port_is_specified
+ test "host with port if http standard port is specified" do
@env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
assert_equal "glu.ttono.us", @request.host_with_port(true)
end
- def test_host_with_port_if_https_standard_port_is_specified
+ test "host with port if https standard port is specified" do
@env['HTTP_X_FORWARDED_PROTO'] = "https"
@env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
assert_equal "glu.ttono.us", @request.host_with_port(true)
end
- def test_host_if_ipv6_reference
+ test "host if ipv6 reference" do
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true)
end
- def test_host_if_ipv6_reference_with_port
+ test "host if ipv6 reference with port" do
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true)
end
- def test_cgi_environment_variables
+ test "cgi environment variables" do
assert_equal "Basic", @request.auth_type
assert_equal 0, @request.content_length
assert_equal nil, @request.content_type
@@ -151,7 +150,7 @@ def test_cgi_environment_variables
assert_equal "lighttpd", @request.server_software
end
- def test_cookie_syntax_resilience
+ test "cookie syntax resilience" do
cookies = @request.cookies
assert_equal "c84ace84796670c052c6ceb2451fb0f2", cookies["_session_id"], cookies.inspect
assert_equal "yes", cookies["is_admin"], cookies.inspect
@@ -163,32 +162,32 @@ def test_cookie_syntax_resilience
end
class RackRequestParamsParsingTest < BaseRackTest
- def test_doesnt_break_when_content_type_has_charset
+ test "doesnt break when content type has charset" do
set_content_data 'flamenco=love'
assert_equal({"flamenco"=> "love"}, @request.request_parameters)
end
- def test_doesnt_interpret_request_uri_as_query_string_when_missing
+ test "doesnt interpret request uri as query string when missing" do
@request.env['REQUEST_URI'] = 'foo'
assert_equal({}, @request.query_parameters)
end
end
class RackRequestContentTypeTest < BaseRackTest
- def test_html_content_type_verification
+ test "html content type verification" do
@request.env['CONTENT_TYPE'] = Mime::HTML.to_s
assert @request.content_type.verify_request?
end
- def test_xml_content_type_verification
+ test "xml content type verification" do
@request.env['CONTENT_TYPE'] = Mime::XML.to_s
assert !@request.content_type.verify_request?
end
end
class RackRequestNeedsRewoundTest < BaseRackTest
- def test_body_should_be_rewound
+ test "body should be rewound" do
data = 'foo'
@env['rack.input'] = StringIO.new(data)
@env['CONTENT_LENGTH'] = data.length
@@ -209,7 +208,7 @@ def setup
@response = ActionDispatch::Response.new
end
- def test_simple_output
+ test "simple output" do
@response.body = "Hello, World!"
@response.prepare!
@@ -228,7 +227,7 @@ def test_simple_output
assert_equal ["Hello, World!"], parts
end
- def test_streaming_block
+ test "streaming block" do
@response.body = Proc.new do |response, output|
5.times { |n| output.write(n) }
end
@@ -256,7 +255,7 @@ def setup
@response.status = "200 OK"
end
- def test_content_type
+ test "content type" do
[204, 304].each do |c|
@response.status = c.to_s
assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
@@ -268,7 +267,7 @@ def test_content_type
end
end
- def test_status
+ test "status" do
assert !response_headers.has_key?('Status')
end
Oops, something went wrong.

0 comments on commit 85750f2

Please sign in to comment.