Skip to content

Commit

Permalink
Add __instances__ entry when loading from cache (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
burke authored and halostatue committed Apr 11, 2017
1 parent aa499d1 commit 372059b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/mime/types/registry.rb
Expand Up @@ -55,8 +55,9 @@ def load_mode
end

def load_default_mime_types(mode = load_mode)
@__types__ = MIME::Types::Cache.load
unless @__types__
if @__types__ = MIME::Types::Cache.load
__instances__.add(@__types__)
else
@__types__ = MIME::Types::Loader.load(mode)
MIME::Types::Cache.save(@__types__)
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_mime_types_cache.rb
Expand Up @@ -42,6 +42,15 @@ def clear_cache_file
assert_equal(nil, MIME::Types::Cache.load)
end

it 'registers the data to be updated by #add_extensions' do
MIME::Types::Cache.save
reset_mime_types
assert_equal([], MIME::Types.type_for('foo.additional'))
html = MIME::Types['text/html'][0]
html.add_extensions('additional')
assert_equal([html], MIME::Types.type_for('foo.additional'))
end

it 'outputs an error when there is an invalid version' do
v = MIME::Types::Data::VERSION
MIME::Types::Data.send(:remove_const, :VERSION)
Expand Down

0 comments on commit 372059b

Please sign in to comment.