diff options
author | Adrian Setyadi <a.styd@yahoo.com> | 2019-10-17 19:00:09 +0700 |
---|---|---|
committer | Adrian Setyadi <a.styd@yahoo.com> | 2019-10-17 21:31:05 +0700 |
commit | f929afaa7b6529ebe364df5eba7c388805af3a33 (patch) | |
tree | 831efd590629c91bf5adc89d5be916ca36dd207b | |
parent | 0907b80a04ba66fb6aa01b43dfcbdc904d462cca (diff) | |
download | rack-f929afaa7b6529ebe364df5eba7c388805af3a33.tar.gz |
Fix stringify_keys error when other is SessionHash
-rw-r--r-- | lib/rack/session/abstract/id.rb | 8 | ||||
-rw-r--r-- | test/spec_session_abstract_session_hash.rb | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/rack/session/abstract/id.rb b/lib/rack/session/abstract/id.rb index c9258644..b15ee3b8 100644 --- a/lib/rack/session/abstract/id.rb +++ b/lib/rack/session/abstract/id.rb @@ -29,6 +29,14 @@ module Rack end } unless {}.respond_to?(:transform_keys) + def transform_keys(&block) + hash = dup + each do |key, value| + hash[block.call(key)] = value + end + hash + end + include Enumerable attr_writer :id diff --git a/test/spec_session_abstract_session_hash.rb b/test/spec_session_abstract_session_hash.rb index 206e2c1b..5d0d10ce 100644 --- a/test/spec_session_abstract_session_hash.rb +++ b/test/spec_session_abstract_session_hash.rb @@ -44,4 +44,10 @@ describe Rack::Session::Abstract::SessionHash do lambda { hash.fetch(:unknown) }.must_raise KeyError end end + + describe "#stringify_keys" do + it "returns hash or session hash with keys stringified" do + assert_equal({ "foo" => :bar, "baz" => :qux }, hash.send(:stringify_keys, hash).to_h) + end + end end |