aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-11-27 11:31:17 +0000
committerJon Leighton <j@jonathanleighton.com>2010-11-27 11:31:17 +0000
commit3a7f43ca6ecf1735e1a82d4a68ac8f62b5cf2fcf (patch)
tree4960911c58f2c47ecaf4f4579167270ba9c257a7 /actionpack/test/dispatch
parent1bc90044b655572a4b8aa3b323905e26d37e0f2b (diff)
parentfd83f9d51583c080072dc9fd00f02ad742e265d4 (diff)
downloadrails-3a7f43ca6ecf1735e1a82d4a68ac8f62b5cf2fcf.tar.gz
rails-3a7f43ca6ecf1735e1a82d4a68ac8f62b5cf2fcf.tar.bz2
rails-3a7f43ca6ecf1735e1a82d4a68ac8f62b5cf2fcf.zip
Merge branch 'master' into nested_has_many_through
Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/associations.rb
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb59
-rw-r--r--actionpack/test/dispatch/request_test.rb14
-rw-r--r--actionpack/test/dispatch/routing_test.rb11
-rw-r--r--actionpack/test/dispatch/uploaded_file_test.rb12
4 files changed, 91 insertions, 5 deletions
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index 4c2b95550c..9424d88498 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -6,10 +6,65 @@ class MimeTypeTest < ActiveSupport::TestCase
test "parse single" do
Mime::LOOKUP.keys.each do |mime_type|
- assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type)
+ unless mime_type == 'image/*'
+ assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type)
+ end
end
end
+ test "unregister" do
+ begin
+ Mime::Type.register("text/x-mobile", :mobile)
+ assert defined?(Mime::MOBILE)
+ assert_equal Mime::MOBILE, Mime::LOOKUP['text/x-mobile']
+ assert_equal Mime::MOBILE, Mime::EXTENSION_LOOKUP['mobile']
+
+ Mime::Type.unregister("text/x-mobile", :mobile)
+ assert !defined?(Mime::MOBILE), "Mime::MOBILE should not be defined"
+ assert !Mime::LOOKUP.has_key?('text/x-mobile'), "Mime::LOOKUP should not have key ['text/x-mobile]"
+ assert !Mime::EXTENSION_LOOKUP.has_key?('mobile'), "Mime::EXTENSION_LOOKUP should not have key ['mobile]"
+ ensure
+ Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
+ Mime::LOOKUP.reject!{|key,_| key == 'text/x-mobile'}
+ end
+ end
+
+ test "parse text with trailing star at the beginning" do
+ accept = "text/*, text/html, application/json, multipart/form-data"
+ expect = [Mime::JSON, Mime::XML, Mime::ICS, Mime::HTML, Mime::CSS, Mime::CSV, Mime::TEXT, Mime::YAML, Mime::JS, Mime::MULTIPART_FORM]
+ parsed = Mime::Type.parse(accept)
+ assert_equal expect.size, parsed.size
+ Range.new(0,expect.size-1).to_a.each do |index|
+ assert_equal expect[index], parsed[index], "Failed for index number #{index}"
+ end
+ end
+
+ test "parse text with trailing star in the end" do
+ accept = "text/html, application/json, multipart/form-data, text/*"
+ expect = [Mime::HTML, Mime::JSON, Mime::MULTIPART_FORM, Mime::XML, Mime::ICS, Mime::CSS, Mime::CSV, Mime::JS, Mime::YAML, Mime::TEXT]
+ parsed = Mime::Type.parse(accept)
+ assert_equal 10, parsed.size
+ Range.new(0,expect.size-1).to_a.each do |index|
+ assert_equal expect[index], parsed[index], "Failed for index number #{index}"
+ end
+ end
+
+ test "parse text with trailing star" do
+ accept = "text/*"
+ expect = [Mime::JSON, Mime::XML, Mime::ICS, Mime::HTML, Mime::CSS, Mime::CSV, Mime::JS, Mime::YAML, Mime::TEXT].sort_by(&:to_s)
+ parsed = Mime::Type.parse(accept)
+ assert_equal 9, parsed.size
+ assert_equal expect, parsed.sort_by(&:to_s)
+ end
+
+ test "parse application with trailing star" do
+ accept = "application/*"
+ expect = [Mime::HTML, Mime::JS, Mime::XML, Mime::YAML, Mime::ATOM, Mime::JSON, Mime::RSS, Mime::PDF, Mime::URL_ENCODED_FORM].sort_by(&:to_s)
+ parsed = Mime::Type.parse(accept)
+ assert_equal 9, parsed.size
+ assert_equal expect, parsed.sort_by(&:to_s)
+ end
+
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]
@@ -44,7 +99,7 @@ class MimeTypeTest < ActiveSupport::TestCase
assert_equal Mime::GIF, Mime::SET.last
end
ensure
- Mime.module_eval { remove_const :GIF if const_defined?(:GIF) }
+ Mime::Type.unregister('image/gif', :gif)
end
end
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 4764a8c2a8..8f672c1149 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -164,12 +164,20 @@ class RequestTest < ActiveSupport::TestCase
assert !request.standard_port?
end
+ test "optional port" do
+ request = stub_request 'HTTP_HOST' => 'www.example.org:80'
+ assert_equal nil, request.optional_port
+
+ request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
+ assert_equal 8080, request.optional_port
+ end
+
test "port string" do
request = stub_request 'HTTP_HOST' => 'www.example.org:80'
- assert_equal "", request.port_string
+ assert_equal '', request.port_string
request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
- assert_equal ":8080", request.port_string
+ assert_equal ':8080', request.port_string
end
test "full path" do
@@ -392,7 +400,7 @@ class RequestTest < ActiveSupport::TestCase
mock_rack_env = { "QUERY_STRING" => "x[y]=1&x[y][][w]=2", "rack.input" => "foo" }
request = nil
begin
- request = stub_request(mock_rack_env)
+ request = stub_request(mock_rack_env)
request.parameters
rescue TypeError => e
# rack will raise a TypeError when parsing this query string
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 0ac8c249cb..bbd010ea6d 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -155,6 +155,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
resources :replies do
+ collection do
+ get 'page/:page' => 'replies#index', :page => %r{\d+}
+ get ':page' => 'replies#index', :page => %r{\d+}
+ end
+
new do
post :preview
end
@@ -1241,6 +1246,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_dynamically_generated_helpers_on_collection_do_not_clobber_resources_url_helper
+ with_test_routes do
+ assert_equal '/replies', replies_path
+ end
+ end
+
def test_scoped_controller_with_namespace_and_action
with_test_routes do
assert_equal '/account/twitter/callback', account_callback_path("twitter")
diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb
index b51697b930..e2a7f1bad7 100644
--- a/actionpack/test/dispatch/uploaded_file_test.rb
+++ b/actionpack/test/dispatch/uploaded_file_test.rb
@@ -28,6 +28,18 @@ module ActionDispatch
assert_equal 'foo', uf.tempfile
end
+ def test_delegates_path_to_tempfile
+ tf = Class.new { def path; 'thunderhorse' end }
+ uf = Http::UploadedFile.new(:tempfile => tf.new)
+ assert_equal 'thunderhorse', uf.path
+ end
+
+ def test_delegates_open_to_tempfile
+ tf = Class.new { def open; 'thunderhorse' end }
+ uf = Http::UploadedFile.new(:tempfile => tf.new)
+ assert_equal 'thunderhorse', uf.open
+ end
+
def test_delegates_to_tempfile
tf = Class.new { def read; 'thunderhorse' end }
uf = Http::UploadedFile.new(:tempfile => tf.new)