diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-04-26 14:33:57 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-04-26 14:33:57 -0500 |
commit | 04949096797a390105c7ab9fb9b99938d5921dd4 (patch) | |
tree | 16316242f307d2f7a41189720ff10ebf44770b50 /actionpack/lib/action_controller | |
parent | c8919f4c7ca13ad78987ea0c8497abe85249975b (diff) | |
download | rails-04949096797a390105c7ab9fb9b99938d5921dd4.tar.gz rails-04949096797a390105c7ab9fb9b99938d5921dd4.tar.bz2 rails-04949096797a390105c7ab9fb9b99938d5921dd4.zip |
Inherit TestSession from Session::AbstractStore and add indifferent access to Session::AbstractStore.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/base/base.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_controller/testing/process.rb | 78 |
2 files changed, 12 insertions, 76 deletions
diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb index 3000b3d12f..afb9fb71cb 100644 --- a/actionpack/lib/action_controller/base/base.rb +++ b/actionpack/lib/action_controller/base/base.rb @@ -811,14 +811,8 @@ module ActionController #:nodoc: end def assign_shortcuts(request, response) - @_request, @_params = request, request.parameters - - @_response = response - @_response.session = request.session - - @_session = @_response.session - - @_headers = @_response.headers + @_request, @_response, @_params = request, response, request.parameters + @_session, @_headers = @_request.session, @_response.headers end def initialize_current_url diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index 2ad0579a30..16275371ad 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -1,8 +1,9 @@ require 'rack/session/abstract/id' + module ActionController #:nodoc: class TestRequest < ActionDispatch::Request #:nodoc: - attr_accessor :cookies, :session_options - attr_accessor :query_parameters, :path, :session + attr_accessor :cookies + attr_accessor :query_parameters, :path attr_accessor :host def self.new(env = {}) @@ -13,18 +14,13 @@ module ActionController #:nodoc: super(Rack::MockRequest.env_for("/").merge(env)) @query_parameters = {} - @session = TestSession.new - default_rack_options = Rack::Session::Abstract::ID::DEFAULT_OPTIONS - @session_options ||= {:id => generate_sid(default_rack_options[:sidbits])}.merge(default_rack_options) + @env['rack.session'] = TestSession.new + @env['rack.session.options'] = TestSession::DEFAULT_OPTIONS.merge(:id => ActiveSupport::SecureRandom.hex(16)) initialize_default_values initialize_containers end - def reset_session - @session.reset - end - # Wraps raw_post in a StringIO. def body_stream #:nodoc: StringIO.new(raw_post) @@ -124,10 +120,6 @@ module ActionController #:nodoc: end private - def generate_sid(sidbits) - "%0#{sidbits / 4}x" % rand(2**sidbits - 1) - end - def initialize_containers @cookies = {} end @@ -235,62 +227,12 @@ module ActionController #:nodoc: end end - class TestSession < Hash #:nodoc: - attr_accessor :session_id - - def initialize(attributes = nil) - reset_session_id - replace_attributes(attributes) - end - - def reset - reset_session_id - replace_attributes({ }) - end - - def data - to_hash - end - - def [](key) - super(key.to_s) - end - - def []=(key, value) - super(key.to_s, value) - end - - def update(hash = nil) - if hash.nil? - ActiveSupport::Deprecation.warn('use replace instead', caller) - replace({}) - else - super(hash) - end - end - - def delete(key = nil) - if key.nil? - ActiveSupport::Deprecation.warn('use clear instead', caller) - clear - else - super(key.to_s) - end - end - - def close - ActiveSupport::Deprecation.warn('sessions should no longer be closed', caller) - end - - private - - def reset_session_id - @session_id = '' - end + class TestSession < ActionDispatch::Session::AbstractStore::SessionHash #:nodoc: + DEFAULT_OPTIONS = ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS - def replace_attributes(attributes = nil) - attributes ||= {} - replace(attributes.stringify_keys) + def initialize(session = {}) + replace(session.stringify_keys) + @loaded = true end end |