Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more tests for sessions

  • Loading branch information...
commit 654eebb0548320ae7ae9f72977957fe4ad87ca3a 1 parent 93d6e1f
@rkh rkh authored
Showing with 36 additions and 0 deletions.
  1. +1 −0  lib/sinatra/base.rb
  2. +6 −0 test/helper.rb
  3. +29 −0 test/helpers_test.rb
View
1  lib/sinatra/base.rb
@@ -1232,6 +1232,7 @@ def new(*args, &bk)
# an instance of this class as end point.
def build(*args, &bk)
builder = Rack::Builder.new
+ setup_sessions builder
builder.use Rack::CommonLogger if logging?
builder.use Rack::MethodOverride if method_override?
builder.use ShowExceptions if show_exceptions?
View
6 test/helper.rb
@@ -25,6 +25,12 @@ class Sinatra::Base
include Test::Unit::Assertions
end
+class Rack::Builder
+ def include?(middleware)
+ @ins.any? { |m| p m ; middleware === m }
+ end
+end
+
Sinatra::Base.set :environment, :test
class Test::Unit::TestCase
View
29 test/helpers_test.rb
@@ -255,6 +255,35 @@ def test_default
follow_redirect!
assert_equal 'hi bar', body
end
+
+ it 'inserts session middleware' do
+ mock_app do
+ enable :sessions
+ get '/' do
+ assert env['rack.session']
+ assert env['rack.session.options']
+ 'ok'
+ end
+ end
+
+ get '/'
+ assert_body 'ok'
+ end
+
+ it 'sets a default session secret' do
+ mock_app do
+ enable :sessions
+ get '/' do
+ secret = env['rack.session.options'][:secret]
+ assert secret
+ assert_equal secret, settings.session_secret
+ 'ok'
+ end
+ end
+
+ get '/'
+ assert_body 'ok'
+ end
end
describe 'mime_type' do
Please sign in to comment.
Something went wrong with that request. Please try again.