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

Set Container default_proc when marshal loaded #86

Merged
merged 1 commit into from
Dec 9, 2014
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
1 change: 1 addition & 0 deletions lib/mime/types/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def marshal_dump
end

def marshal_load(hash)
self.default_proc = ->(h, k) { h[k] = [] }
self.merge!(hash)
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_mime_types_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ def test_cache_load_failure
MIME::Types['text/html']
end
end

def test_container_marshalling
container = MIME::Types::Container.new
# default proc should return []
assert_equal([], container['abc'])

marshalled = Marshal.dump(container)
loaded_container = Marshal.load(marshalled)

# default proc should still return []
assert_equal([], loaded_container['abcd'])
end
end