diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-01-20 22:55:25 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-01-20 22:55:25 +0000 |
commit | 250a1194b91e6ddb3e2e80d48753a1591992164b (patch) | |
tree | 70d1fbba378c76a9ccdacac0e855d6b4c187f324 | |
parent | 88bc014acc82129e55a7ae7505cb62bacd0d685d (diff) | |
download | rails-250a1194b91e6ddb3e2e80d48753a1591992164b.tar.gz rails-250a1194b91e6ddb3e2e80d48753a1591992164b.tar.bz2 rails-250a1194b91e6ddb3e2e80d48753a1591992164b.zip |
Ensure mime types can be compared with symbols. Closes #10796 [bscofield]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8677 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/mime_type_test.rb | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index ec9d2eea6d..16e3ffc9c1 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -145,7 +145,10 @@ module Mime end def ==(mime_type) - (@synonyms + [ self ]).any? { |synonym| synonym.to_s == mime_type.to_s } if mime_type + return false unless mime_type + (@synonyms + [ self ]).any? do |synonym| + synonym.to_s == mime_type.to_s || synonym.to_sym == mime_type.to_sym + end end private diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb index 5f29393fce..991ac04f62 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/controller/mime_type_test.rb @@ -39,6 +39,11 @@ class MimeTypeTest < Test::Unit::TestCase Mime.module_eval { remove_const :GIF if const_defined?(:GIF) } end + def test_type_should_be_equal_to_symbol + assert_equal Mime::HTML, 'application/xhtml+xml' + assert_equal Mime::HTML, :html + end + def test_type_convenience_methods types = [:html, :xml, :png, :pdf, :yaml, :url_encoded_form] types.each do |type| |