Skip to content

Commit

Permalink
Merge pull request #981 from michaelsauter/fix/load-for-read
Browse files Browse the repository at this point in the history
Load session for read before accessing keys or values
  • Loading branch information
matthewd committed Jan 1, 2016
2 parents 7cb3772 + 5de59df commit a7b3c3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/session/abstract/id.rb
Expand Up @@ -124,10 +124,12 @@ def empty?
end

def keys
load_for_read!
@data.keys
end

def values
load_for_read!
@data.values
end

Expand Down
28 changes: 28 additions & 0 deletions test/spec_session_abstract_session_hash.rb
@@ -0,0 +1,28 @@
require 'minitest/autorun'
require 'rack/session/abstract/id'

describe Rack::Session::Abstract::SessionHash do
attr_reader :hash

def setup
super
store = Class.new do
def load_session(req)
["id", {foo: :bar, baz: :qux}]
end
def session_exists?(req)
true
end
end
@hash = Rack::Session::Abstract::SessionHash.new(store.new, nil)
end

it "returns keys" do
assert_equal ["foo", "baz"], hash.keys
end

it "returns values" do
assert_equal [:bar, :qux], hash.values
end

end

0 comments on commit a7b3c3c

Please sign in to comment.