diff options
author | Rafael França <rafael@franca.dev> | 2019-10-17 14:38:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-17 14:38:39 -0400 |
commit | 4ffc2741ac4e54abe4f12b4c058376d6c7e770ed (patch) | |
tree | 7b5e95acfd239df9c79532d7b346c6c61d23a10b | |
parent | 5f995a541b860d98ece4df3d550201db6f8eb372 (diff) | |
parent | f929afaa7b6529ebe364df5eba7c388805af3a33 (diff) | |
download | rack-4ffc2741ac4e54abe4f12b4c058376d6c7e770ed.tar.gz |
Merge pull request #1401 from styd/stringify-keys-session-hash
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 |