Skip to content

Commit

Permalink
Set Container default_proc when marshal loaded
Browse files Browse the repository at this point in the history
Marshal.load does not initialize the object so the default_proc doesn't get set when loaded from the cache
  • Loading branch information
albus522 committed Dec 9, 2014
1 parent 60cf36b commit bf46fc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit bf46fc7

Please sign in to comment.