aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Prats <tprats108@gmail.com>2015-07-12 02:01:30 -0400
committerTom Prats <tprats108@gmail.com>2016-01-29 17:22:05 -0500
commit82dc8266dddc199789f3f1e9a9f21975e1c8ee87 (patch)
treec7b1747445c3bd5d76933eaf49e6022a8128ceeb
parent513f72804d800bb9a028f6ffc66ab1a0b45df26f (diff)
downloadrails-82dc8266dddc199789f3f1e9a9f21975e1c8ee87.tar.gz
rails-82dc8266dddc199789f3f1e9a9f21975e1c8ee87.tar.bz2
rails-82dc8266dddc199789f3f1e9a9f21975e1c8ee87.zip
Update session to have indifferent access
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_dispatch/request/session.rb4
-rw-r--r--actionpack/test/dispatch/request/session_test.rb10
3 files changed, 21 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index f6ffe45490..2a29a9fdf1 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,12 @@
+* Update session to have indifferent access across multiple requests
+
+ session[:deep][:hash] = "Magic"
+
+ session[:deep][:hash] == "Magic"
+ session[:deep]["hash"] == "Magic"
+
+ *Tom Prats*
+
* Response etags to always be weak: Prefixes 'W/' to value returned by
`ActionDispatch::Http::Cache::Response#etag=`, such that etags set in
`fresh_when` and `stale?` are weak.
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
index 42890225fa..f6428af636 100644
--- a/actionpack/lib/action_dispatch/request/session.rb
+++ b/actionpack/lib/action_dispatch/request/session.rb
@@ -9,7 +9,7 @@ module ActionDispatch
# Singleton object used to determine if an optional param wasn't specified
Unspecified = Object.new
-
+
# Creates a session hash, merging the properties of the previous session if any
def self.create(store, req, default_options)
session_was = find req
@@ -61,7 +61,7 @@ module ActionDispatch
def initialize(by, req)
@by = by
@req = req
- @delegate = {}
+ @delegate = {}.with_indifferent_access
@loaded = false
@exists = nil # we haven't checked yet
end
diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb
index 7dcbcc5c21..3fc4ffd71c 100644
--- a/actionpack/test/dispatch/request/session_test.rb
+++ b/actionpack/test/dispatch/request/session_test.rb
@@ -105,6 +105,16 @@ module ActionDispatch
end
end
+ def test_with_indifferent_access
+ s = Session.create(store, req, {})
+
+ s[:one] = { test: "deep" }
+ s[:two] = { "test" => "deep" }
+
+ assert_equal 'deep', s[:one]["test"]
+ assert_equal 'deep', s[:two][:test]
+ end
+
private
def store
Class.new {