Skip to content
Browse files

accept a hash as sessions setting

  • Loading branch information...
1 parent eb28713 commit 0c9e3d869e36b449f68990aeca099e1a422026df @rkh rkh committed Mar 19, 2011
Showing with 23 additions and 1 deletion.
  1. +2 −0 CHANGES
  2. +5 −0 README.rdoc
  3. +3 −1 lib/sinatra/base.rb
  4. +13 −0 test/helpers_test.rb
View
2 CHANGES
@@ -2,6 +2,8 @@
* Added support for HTTP PATCH requests. (Konstantin Haase)
+ * The sessions setting now may be an options hash. (Konstantin Haase)
+
* Important: 1.8.6 support has been dropped. (Konstantin Haase)
= 1.2.1 / 2011-03-17
View
5 README.rdoc
@@ -810,6 +810,11 @@ set the secret yourself, so all your application instances share it:
set :session_secret, 'super secret'
+If you want to configure it further, you may also store a hash with options in
+the +sessions+ setting:
+
+ set :sessions, :domain => 'foo.com'
+
=== Halting
To immediately stop a request within a filter or route use:
View
4 lib/sinatra/base.rb
@@ -1248,7 +1248,9 @@ def call(env)
private
def setup_sessions(builder)
return unless sessions?
- builder.use Rack::Session::Cookie, :secret => session_secret
+ options = { :secret => session_secret }
+ options.merge! sessions.to_hash if sessions.respond_to? :to_hash
+ builder.use Rack::Session::Cookie, options
end
def detect_rack_handler
View
13 test/helpers_test.rb
@@ -284,6 +284,19 @@ def test_default
get '/'
assert_body 'ok'
end
+
+ it 'accepts an options hash' do
+ mock_app do
+ set :sessions, :foo => :bar
+ get '/' do
+ assert_equal env['rack.session.options'][:foo], :bar
+ 'ok'
+ end
+ end
+
+ get '/'
+ assert_body 'ok'
+ end
end
describe 'mime_type' do

0 comments on commit 0c9e3d8

Please sign in to comment.
Something went wrong with that request. Please try again.