fix two MimeType failing test cases

Signed-off-by: Michael Koziarski <michael@koziarski.com>
This commit is contained in:
rick 2008-11-12 13:34:29 -08:00 committed by Michael Koziarski
parent fbbcd6f29a
commit 00c46b5eeb
2 changed files with 10 additions and 7 deletions

@ -20,8 +20,11 @@ module Mime
# end
class Type
@@html_types = Set.new [:html, :url_encoded_form, :multipart_form, :all]
cattr_reader :html_types
# UNUSED, deprecate?
@@unverifiable_types = Set.new [:text, :json, :csv, :xml, :rss, :atom, :yaml]
cattr_reader :html_types, :unverifiable_types
cattr_reader :unverifiable_types
# A simple helper class used in parsing the accept header
class AcceptItem #:nodoc:

@ -61,7 +61,9 @@ def test_type_convenience_methods
types.each do |type|
mime = Mime.const_get(type.to_s.upcase)
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
(types - [type]).each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
invalid_types = types - [type]
invalid_types.delete(:html) if Mime::Type.html_types.include?(type)
invalid_types.each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
end
end
@ -71,14 +73,12 @@ def test_mime_all_is_html
end
def test_verifiable_mime_types
unverified_types = Mime::Type.unverifiable_types
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
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
unverified, verified = all_types.partition { |type| Mime::Type.unverifiable_types.include? type }
assert verified.all? { |type| Mime.const_get(type.to_s.upcase).verify_request? }, "Not all Mime Types are verified: #{verified.inspect}"
assert unverified.all? { |type| !Mime.const_get(type.to_s.upcase).verify_request? }, "Some Mime Types are verified: #{unverified.inspect}"
verified, unverified = all_types.partition { |type| Mime::Type.html_types.include? type }
assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Mime Type is not verified: #{type.inspect}" }
assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Mime Type is verified: #{type.inspect}" }
end
end