Permalink
Browse files

Use regular constructor of MIME::Type

- remove redundant mime-types
- add missing specs

Fixes #13
  • Loading branch information...
1 parent e46ce3b commit 59e5590e1e40738ab62be45865f3d9aef5bb89b3 @copiousfreetime committed Oct 16, 2013
Showing with 19 additions and 10 deletions.
  1. +5 −9 lib/heel/mime_map.rb
  2. +13 −0 spec/directory_indexer_spec.rb
  3. +1 −1 spec/rackapp_spec.rb
View
@@ -38,23 +38,19 @@ def icons_by_mime_type
# mime-types calls.
def additional_mime_types
[
- { 'Content-Type' => 'images/svg+xml', 'Extensions' => %w[ svg ] },
- { 'Content-Type' => 'video/x-flv', 'Extensions' => %w[ flv ] },
- { 'Content-Type' => 'application/x-shockwave-flash', 'Extensions' => %w[ swf ] },
- { 'Content-Type' => 'text/plain', 'Extensions' => %w[ rb rhtml md markdown ] },
+ MIME::Type.new( 'text/plain' ) { |t| t.extensions = %w[ rb rdoc rhtml md markdown ] },
]
end
end
def initialize
MimeMap.additional_mime_types.each do |mt|
- existing_type = MIME::Types[mt['Content-Type']]
+ existing_type = MIME::Types[mt]
if existing_type.empty? then
- type = MIME::Type.from_hash(mt)
- MIME::Types.add(type)
+ MIME::Types.add(mt)
else
type = existing_type.first
- mt['Extensions'].each do |ext|
+ mt.extensions.each do |ext|
type.extensions << ext unless type.extensions.include?( ext )
end
# have to reindex if new extensions added
@@ -70,7 +66,7 @@ def default_mime_type
# returns the mime type of the file at a given pathname
#
def mime_type_of(f)
- MIME::Types.of(f).first || default_mime_type
+ MIME::Types.of(f).last || default_mime_type
end
# return the icon name for a particular mime type
@@ -31,4 +31,17 @@
@indexer.mime_map.must_be_instance_of(Heel::MimeMap)
end
+ [ { :ext => 'svg', :type => 'image/svg+xml' },
+ { :ext => 'flv', :type => 'video/x-flv' },
+ { :ext => 'swf', :type => 'application/x-shockwave-flash' } ].each do |m|
+ it "finds #{m[:ext]} extension in the map as #{m[:type]}" do
+ @indexer.mime_map.mime_type_of( "test.#{m[:ext]}" ).must_equal m[:type]
+ end
+ end
+
+ %w[ md markdown rdoc rb rhtml ].each do |ext|
+ it "finds #{ext} in the map as text/plain" do
+ @indexer.mime_map.mime_type_of( "test.#{ext}" ).must_equal "text/plain"
+ end
+ end
end
View
@@ -26,7 +26,7 @@
res = @request.get("/lib/heel.rb?highlighting=off")
res.must_be :ok?
res.body.size.must_equal File.size("lib/heel.rb")
- res['Content-Type'].must_equal "application/x-ruby"
+ res['Content-Type'].must_equal "text/plain"
end
it "should return a 405 if given a non-GET request" do

0 comments on commit 59e5590

Please sign in to comment.