mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
added tests for session options being defaulted correctly to rack defaults [#2403 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
651611999d
commit
ace154d067
3 changed files with 42 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
|||
require 'rack/session/abstract/id'
|
||||
module ActionController #:nodoc:
|
||||
class TestRequest < Request #:nodoc:
|
||||
attr_accessor :cookies, :session_options
|
||||
|
@ -13,7 +14,8 @@ module ActionController #:nodoc:
|
|||
|
||||
@query_parameters = {}
|
||||
@session = TestSession.new
|
||||
@session_options ||= {}
|
||||
default_rack_options = Rack::Session::Abstract::ID::DEFAULT_OPTIONS
|
||||
@session_options ||= {:id => generate_sid(default_rack_options[:sidbits])}.merge(default_rack_options)
|
||||
|
||||
initialize_default_values
|
||||
initialize_containers
|
||||
|
@ -122,6 +124,10 @@ module ActionController #:nodoc:
|
|||
end
|
||||
|
||||
private
|
||||
def generate_sid(sidbits)
|
||||
"%0#{sidbits / 4}x" % rand(2**sidbits - 1)
|
||||
end
|
||||
|
||||
def initialize_containers
|
||||
@cookies = {}
|
||||
end
|
||||
|
|
35
actionpack/test/controller/request/test_request_test.rb
Normal file
35
actionpack/test/controller/request/test_request_test.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'abstract_unit'
|
||||
require 'stringio'
|
||||
|
||||
class ActionController::TestRequestTest < ActiveSupport::TestCase
|
||||
|
||||
def setup
|
||||
@request = ActionController::TestRequest.new
|
||||
end
|
||||
|
||||
def test_test_request_has_session_options_initialized
|
||||
assert @request.session_options
|
||||
end
|
||||
|
||||
Rack::Session::Abstract::ID::DEFAULT_OPTIONS.each_key do |option|
|
||||
test "test_rack_default_session_options_#{option}_exists_in_session_options_and_is_default" do
|
||||
assert_equal(Rack::Session::Abstract::ID::DEFAULT_OPTIONS[option],
|
||||
@request.session_options[option],
|
||||
"Missing rack session default option #{option} in request.session_options")
|
||||
end
|
||||
test "test_rack_default_session_options_#{option}_exists_in_session_options" do
|
||||
assert(@request.session_options.has_key?(option),
|
||||
"Missing rack session option #{option} in request.session_options")
|
||||
end
|
||||
end
|
||||
|
||||
def test_session_id_exists_by_default
|
||||
assert_not_nil(@request.session_options[:id])
|
||||
end
|
||||
|
||||
def test_session_id_different_on_each_call
|
||||
prev_id =
|
||||
assert_not_equal(@request.session_options[:id], ActionController::TestRequest.new.session_options[:id])
|
||||
end
|
||||
|
||||
end
|
|
@ -130,10 +130,6 @@ XML
|
|||
ActionController::Routing::Routes.reload
|
||||
end
|
||||
|
||||
def test_test_request_has_session_options_initialized
|
||||
assert @request.session_options
|
||||
end
|
||||
|
||||
def test_raw_post_handling
|
||||
params = {:page => {:name => 'page name'}, 'some key' => 123}
|
||||
post :render_raw_post, params.dup
|
||||
|
|
Loading…
Reference in a new issue