Fix Hashie::Rash randomly losing keys (#430)

This commit is contained in:
Andrii Dmytrenko 2017-12-19 20:37:09 +00:00 committed by Michael Herold
parent 32514df065
commit dabdcd17e7
3 changed files with 9 additions and 1 deletions

View File

@ -28,6 +28,8 @@ scheme are considered to be bugs.
### Fixed
[#430](https://github.com/intridea/hashie/pull/430): Fix Hashie::Rash randomly losing items - [@Antti](https://github.com/Antti)
* Your contribution here.
### Security

View File

@ -136,7 +136,7 @@ module Hashie
def optimize_if_necessary!
return unless (@lookups += 1) >= @optimize_every
@regexes = @regex_counts.sort_by { |_, count| -count }.map { |regex, _| regex }
@regexes = @regexes.sort_by { |regex| -@regex_counts[regex] }
@lookups = 0
end
end

View File

@ -74,4 +74,10 @@ describe Hashie::Rash do
expect(subject.respond_to?(:to_a)).to be true
expect(subject.methods).to_not include(:to_a)
end
it 'does not lose keys' do
subject.optimize_every = 1
expect(subject['hello']).to eq('hello')
expect(subject['world']).to eq('world')
end
end