Skip to content

Commit

Permalink
fix two MimeType failing test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
technoweenie authored and NZKoz committed Nov 13, 2008
1 parent fbbcd6f commit 00c46b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion actionpack/lib/action_controller/mime_type.rb
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions actionpack/test/controller/mime_type_test.rb
Expand Up @@ -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

Expand All @@ -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

0 comments on commit 00c46b5

Please sign in to comment.