Fix Hashie::Rash randomly losing keys (#430)
This commit is contained in:
parent
32514df065
commit
dabdcd17e7
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue