Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __instances__ entry when loading from cache #126

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/mime/types/registry.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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