aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2019-03-05 23:38:59 -0800
committerJohn Hawthorn <john@hawthorn.email>2019-03-14 11:33:48 -0700
commitb5e8942c95078945ff09a83b2fc03a0ae7e35953 (patch)
treedc35e0dbd8f1b69b6d4770c94ca3454d2ad19f6f /actionpack/test/dispatch
parent43fc7b476b483a89dacf9964ccf288f6bc6e1595 (diff)
downloadrails-b5e8942c95078945ff09a83b2fc03a0ae7e35953.tar.gz
rails-b5e8942c95078945ff09a83b2fc03a0ae7e35953.tar.bz2
rails-b5e8942c95078945ff09a83b2fc03a0ae7e35953.zip
Raise exception when building invalid mime type
This allows mime types in the form text/html, text/*, or */* This required a few minor test/code changes where previously nil was used as a mime string.
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index 45d91883c0..bb3d888e30 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -174,4 +174,36 @@ class MimeTypeTest < ActiveSupport::TestCase
assert_not (Mime[:js] !~ "application/javascript")
assert Mime[:html] =~ "application/xhtml+xml"
end
+
+ test "can be initialized with wildcards" do
+ assert_equal "*/*", Mime::Type.new("*/*").to_s
+ assert_equal "text/*", Mime::Type.new("text/*").to_s
+ assert_equal "video/*", Mime::Type.new("video/*").to_s
+ end
+
+ test "invalid mime types raise error" do
+ assert_raises Mime::Type::InvalidMimeType do
+ Mime::Type.new("too/many/slash")
+ end
+
+ assert_raises Mime::Type::InvalidMimeType do
+ Mime::Type.new("missingslash")
+ end
+
+ assert_raises Mime::Type::InvalidMimeType do
+ Mime::Type.new("text/html, text/plain")
+ end
+
+ assert_raises Mime::Type::InvalidMimeType do
+ Mime::Type.new("*/html")
+ end
+
+ assert_raises Mime::Type::InvalidMimeType do
+ Mime::Type.new("")
+ end
+
+ assert_raises Mime::Type::InvalidMimeType do
+ Mime::Type.new(nil)
+ end
+ end
end