summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Dmytrenko <refresh.xss@gmail.com>2017-12-19 20:37:09 +0000
committerMichael Herold <github@michaeljherold.com>2017-12-19 14:37:09 -0600
commitdabdcd17e7d482cbc7f153ddc20149353d02a56d (patch)
tree9e4c37d6692a43dcb7973846f8d8a803c55ab1d6
parent32514df06550e21dc47d5c989ff6a90ef0c9b9fa (diff)
downloadhashie-dabdcd17e7d482cbc7f153ddc20149353d02a56d.tar.gz
Fix Hashie::Rash randomly losing keys (#430)
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/hashie/rash.rb2
-rw-r--r--spec/hashie/rash_spec.rb6
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2ae6b07..88722f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/lib/hashie/rash.rb b/lib/hashie/rash.rb
index 1e059f3..0024eee 100644
--- a/lib/hashie/rash.rb
+++ b/lib/hashie/rash.rb
@@ -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
diff --git a/spec/hashie/rash_spec.rb b/spec/hashie/rash_spec.rb
index 914e7b4..8e3d4a2 100644
--- a/spec/hashie/rash_spec.rb
+++ b/spec/hashie/rash_spec.rb
@@ -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