Permalink
Browse files

allow passing in rack.session in tests (used to work previously)

  • Loading branch information...
1 parent fc51ee7 commit 0dc6a0a9259aea0bb3951fecc7b5ead3e21d72c0 @rkh rkh committed May 31, 2011
Showing with 9 additions and 1 deletion.
  1. +3 −1 lib/rack/session/abstract/id.rb
  2. +6 −0 test/spec_session_cookie.rb
@@ -222,8 +222,10 @@ def generate_sid(secure = @sid_secure)
# metadata into 'rack.session.options'.
def prepare_session(env)
- env[ENV_SESSION_KEY] = SessionHash.new(self, env)
+ session_was = env[ENV_SESSION_KEY]
+ env[ENV_SESSION_KEY] = SessionHash.new(self, env)
env[ENV_SESSION_OPTIONS_KEY] = OptionsHash.new(self, env, @default_options)
+ env[ENV_SESSION_KEY].merge! session_was if session_was
end
# Extracts the session id from provided cookies and passes it and the
@@ -207,4 +207,10 @@ def decode(str); @calls << :decode; str; end
res = Rack::MockRequest.new(app).get("/")
res.body.should.match(/Base64::Marshal/)
end
+
+ it "allows passing in a hash with session data from middleware in front" do
+ app = Rack::Session::Cookie.new(session_id)
+ res = Rack::MockRequest.new(app).get("/", 'rack.session' => {:foo => 'bar'})
+ res.body.should.match(/foo/)
+ end
end

0 comments on commit 0dc6a0a

Please sign in to comment.