Permalink
Browse files

Merge pull request #154 from rkh/session-options

keep :secret and :coder in env["rack.session.options"]
  • Loading branch information...
raggi committed May 8, 2011
2 parents 6437312 + 84472fb commit c16729ddc2a0576818db2e8c20ca6550d9d2cdad
Showing with 20 additions and 2 deletions.
  1. +2 −2 lib/rack/session/cookie.rb
  2. +18 −0 test/spec_session_cookie.rb
@@ -79,8 +79,8 @@ def decode(str); str.reverse; end
attr_reader :coder
def initialize(app, options={})
- @secret = options.delete(:secret)
- @coder = options.delete(:coder) || Base64::Marshal.new
+ @secret = options[:secret]
+ @coder = options[:coder] ||= Base64::Marshal.new
super(app, options.merge!(:cookie_only => true))
end
@@ -14,6 +14,12 @@
Rack::Response.new(env["rack.session"].inspect).to_a
end
+ session_option = lambda do |opt|
+ lambda do |env|
+ Rack::Response.new(env["rack.session.options"][opt].inspect).to_a
+ end
+ end
+
nothing = lambda do |env|
Rack::Response.new("Nothing").to_a
end
@@ -189,4 +195,16 @@ def decode(str); @calls << :decode; str; end
res = Rack::MockRequest.new(app).get("/")
res["Set-Cookie"].should.not.be.nil
end
+
+ it "exposes :secret in env['rack.session.option']" do
+ app = Rack::Session::Cookie.new(session_option[:secret], :secret => "foo")
+ res = Rack::MockRequest.new(app).get("/")
+ res.body.should == '"foo"'
+ end
+
+ it "exposes :coder in env['rack.session.option']" do
+ app = Rack::Session::Cookie.new(session_option[:coder])
+ res = Rack::MockRequest.new(app).get("/")
+ res.body.should.match(/Base64::Marshal/)
+ end
end

0 comments on commit c16729d

Please sign in to comment.