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_dispatch | |
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_dispatch')
4 files changed, 34 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index ab654b9a50..2602b344ca 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -451,23 +451,15 @@ EOM @env['rack.input'] end - def session - @env['rack.session'] ||= {} + def reset_session + self.session_options.delete(:id) + self.session = {} end def session=(session) #:nodoc: @env['rack.session'] = session end - def reset_session - @env['rack.session.options'].delete(:id) - @env['rack.session'] = {} - end - - def session_options - @env['rack.session.options'] ||= {} - end - def session_options=(options) @env['rack.session.options'] = options end diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 7bc9c62e2c..77c2dd0d7a 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -34,12 +34,13 @@ module ActionDispatch # :nodoc: DEFAULT_HEADERS = { "Cache-Control" => "no-cache" } attr_accessor :request - attr_accessor :session, :assigns, :template, :layout + attr_accessor :assigns, :template, :layout attr_accessor :redirected_to, :redirected_to_method_params attr_writer :header alias_method :headers=, :header= + delegate :session, :to => :request delegate :default_charset, :to => 'ActionController::Base' def initialize diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 211d373208..03761b10bd 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -26,12 +26,12 @@ module ActionDispatch def [](key) load! unless @loaded - super + super(key.to_s) end def []=(key, value) load! unless @loaded - super + super(key.to_s, value) end def to_hash @@ -40,6 +40,24 @@ module ActionDispatch h end + def update(hash = nil) + if hash.nil? + ActiveSupport::Deprecation.warn('use replace instead', caller) + replace({}) + else + super(hash.stringify_keys) + 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 data ActiveSupport::Deprecation.warn( "ActionController::Session::AbstractStore::SessionHash#data " + @@ -47,6 +65,10 @@ module ActionDispatch to_hash end + def close + ActiveSupport::Deprecation.warn('sessions should no longer be closed', caller) + end + def inspect load! unless @loaded super @@ -61,7 +83,7 @@ module ActionDispatch stale_session_check! do id, session = @by.send(:load_session, @env) (@env[ENV_SESSION_OPTIONS_KEY] ||= {})[:id] = id - replace(session) + replace(session.stringify_keys) @loaded = true end end diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 433c4cc070..547a2d2062 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -143,7 +143,8 @@ module ActionDispatch request = Rack::Request.new(env) session_data = request.cookies[@key] data = unmarshal(session_data) || persistent_session_id!({}) - [data[:session_id], data] + data.stringify_keys! + [data["session_id"], data] end # Marshal a session hash into safe cookie data. Include an integrity hash. @@ -206,12 +207,12 @@ module ActionDispatch end def inject_persistent_session_id(data) - requires_session_id?(data) ? { :session_id => generate_sid } : {} + requires_session_id?(data) ? { "session_id" => generate_sid } : {} end def requires_session_id?(data) if data - data.respond_to?(:key?) && !data.key?(:session_id) + data.respond_to?(:key?) && !data.key?("session_id") else true end |