Skip to content

Commit

Permalink
more tests for sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Mar 13, 2011
1 parent 93d6e1f commit 654eebb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sinatra/base.rb
Expand Up @@ -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?
Expand Down
6 changes: 6 additions & 0 deletions test/helper.rb
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/helpers_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 654eebb

Please sign in to comment.