aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_controller/test_case.rb2
-rw-r--r--actionpack/lib/action_dispatch/request/session.rb26
-rw-r--r--actionpack/test/dispatch/request/session_test.rb10
-rw-r--r--actionpack/test/dispatch/session/abstract_store_test.rb16
-rw-r--r--actionpack/test/dispatch/session/cache_store_test.rb29
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb34
-rw-r--r--actionpack/test/dispatch/session/mem_cache_store_test.rb31
-rw-r--r--actionpack/test/dispatch/session/test_session_test.rb7
-rw-r--r--guides/source/getting_started.md36
10 files changed, 37 insertions, 163 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 5b762a8f17..6b73b29ace 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -29,15 +29,6 @@
## Rails 5.0.0.beta3 (February 24, 2016) ##
-* Update session to have indifferent access across multiple requests.
-
- session[:deep][:hash] = "Magic"
-
- session[:deep][:hash] == "Magic"
- session[:deep]["hash"] == "Magic"
-
- *Tom Prats*
-
* Add application/gzip as a default mime type.
*Mehmet Emin İNAÇ*
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 6548ce326b..700317614f 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -176,7 +176,7 @@ module ActionController
def initialize(session = {})
super(nil, nil)
@id = SecureRandom.hex(16)
- @data = session.with_indifferent_access
+ @data = stringify_keys(session)
@loaded = true
end
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
index 38d0da3e67..42890225fa 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 = {}.with_indifferent_access
+ @delegate = {}
@loaded = false
@exists = nil # we haven't checked yet
end
@@ -88,13 +88,13 @@ module ActionDispatch
# nil if the given key is not found in the session.
def [](key)
load_for_read!
- @delegate[key]
+ @delegate[key.to_s]
end
# Returns true if the session has the given key or false.
def has_key?(key)
load_for_read!
- @delegate.key?(key)
+ @delegate.key?(key.to_s)
end
alias :key? :has_key?
alias :include? :has_key?
@@ -112,7 +112,7 @@ module ActionDispatch
# Writes given value to given key of the session.
def []=(key, value)
load_for_write!
- @delegate[key] = value
+ @delegate[key.to_s] = value
end
# Clears the session.
@@ -139,13 +139,13 @@ module ActionDispatch
# # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2", "foo" => "bar"}
def update(hash)
load_for_write!
- @delegate.update hash
+ @delegate.update stringify_keys(hash)
end
# Deletes given key from the session.
def delete(key)
load_for_write!
- @delegate.delete key
+ @delegate.delete key.to_s
end
# Returns value of the given key from the session, or raises +KeyError+
@@ -165,9 +165,9 @@ module ActionDispatch
def fetch(key, default=Unspecified, &block)
load_for_read!
if default == Unspecified
- @delegate.fetch(key, &block)
+ @delegate.fetch(key.to_s, &block)
else
- @delegate.fetch(key, default, &block)
+ @delegate.fetch(key.to_s, default, &block)
end
end
@@ -211,9 +211,15 @@ module ActionDispatch
def load!
id, session = @by.load_session @req
options[:id] = id
- @delegate.replace(session)
+ @delegate.replace(stringify_keys(session))
@loaded = true
end
+
+ def stringify_keys(other)
+ other.each_with_object({}) { |(key, value), hash|
+ hash[key.to_s] = value
+ }
+ end
end
end
end
diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb
index 3433d82791..7dcbcc5c21 100644
--- a/actionpack/test/dispatch/request/session_test.rb
+++ b/actionpack/test/dispatch/request/session_test.rb
@@ -105,16 +105,6 @@ module ActionDispatch
end
end
- def test_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 {
diff --git a/actionpack/test/dispatch/session/abstract_store_test.rb b/actionpack/test/dispatch/session/abstract_store_test.rb
index c9ce5cad42..d38d1bbce6 100644
--- a/actionpack/test/dispatch/session/abstract_store_test.rb
+++ b/actionpack/test/dispatch/session/abstract_store_test.rb
@@ -46,22 +46,6 @@ module ActionDispatch
assert_equal session.to_hash, session1.to_hash
end
- def test_previous_session_has_indifferent_access
- env = {}
- as = MemoryStore.new app
- as.call(env)
-
- assert @env
- session = Request::Session.find ActionDispatch::Request.new @env
- session[:foo] = { bar: "baz" }
-
- as.call(@env)
- session = Request::Session.find ActionDispatch::Request.new @env
-
- assert_equal session[:foo][:bar], "baz"
- assert_equal session[:foo]["bar"], "baz"
- end
-
private
def app(&block)
@env = nil
diff --git a/actionpack/test/dispatch/session/cache_store_test.rb b/actionpack/test/dispatch/session/cache_store_test.rb
index b911392cf1..dbb996973d 100644
--- a/actionpack/test/dispatch/session/cache_store_test.rb
+++ b/actionpack/test/dispatch/session/cache_store_test.rb
@@ -12,11 +12,6 @@ class CacheStoreTest < ActionDispatch::IntegrationTest
head :ok
end
- def set_deep_session_value
- session[:foo] = { bar: "baz" }
- head :ok
- end
-
def set_serialized_session_value
session[:foo] = SessionAutoloadTest::Foo.new
head :ok
@@ -26,14 +21,6 @@ class CacheStoreTest < ActionDispatch::IntegrationTest
render plain: "foo: #{session[:foo].inspect}"
end
- def get_deep_session_value_with_symbol
- render plain: "foo: { bar: #{session[:foo][:bar].inspect} }"
- end
-
- def get_deep_session_value_with_string
- render plain: "foo: { \"bar\" => #{session[:foo]["bar"].inspect} }"
- end
-
def get_session_id
render plain: "#{request.session.id}"
end
@@ -173,22 +160,6 @@ class CacheStoreTest < ActionDispatch::IntegrationTest
end
end
- def test_previous_session_has_indifferent_access
- with_test_route_set do
- get '/set_deep_session_value'
- assert_response :success
- assert cookies['_session_id']
-
- get '/get_deep_session_value_with_symbol'
- assert_response :success
- assert_equal 'foo: { bar: "baz" }', response.body
-
- get '/get_deep_session_value_with_string'
- assert_response :success
- assert_equal 'foo: { "bar" => "baz" }', response.body
- end
- end
-
private
def with_test_route_set
with_routing do |set|
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 71402b021a..f07e215e3a 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -24,23 +24,10 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
render plain: Rack::Utils.escape(Verifier.generate(session.to_hash))
end
- def set_deep_session_value
- session[:foo] = { bar: "baz" }
- render plain: Rack::Utils.escape(Verifier.generate(session.to_hash))
- end
-
def get_session_value
render plain: "foo: #{session[:foo].inspect}"
end
- def get_deep_session_value_with_symbol
- render plain: "foo: { bar: #{session[:foo][:bar].inspect} }"
- end
-
- def get_deep_session_value_with_string
- render plain: "foo: { \"bar\" => #{session[:foo]["bar"].inspect} }"
- end
-
def get_session_id
render plain: "id: #{request.session.id}"
end
@@ -94,15 +81,6 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
end
end
- def test_session_indifferent_access
- with_test_route_set do
- cookies[SessionKey] = SignedBar
- get '/get_session_value'
- assert_response :success
- assert_equal 'foo: "bar"', response.body
- end
- end
-
def test_getting_session_id
with_test_route_set do
cookies[SessionKey] = SignedBar
@@ -354,18 +332,6 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
end
end
- def test_previous_session_has_indifferent_access
- with_test_route_set do
- get '/set_deep_session_value'
-
- get '/get_deep_session_value_with_symbol'
- assert_equal 'foo: { bar: "baz" }', response.body
-
- get '/get_deep_session_value_with_string'
- assert_equal 'foo: { "bar" => "baz" }', response.body
- end
- end
-
private
# Overwrite get to send SessionSecret in env hash
diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb
index 2e6b42856f..3fed9bad4f 100644
--- a/actionpack/test/dispatch/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
@@ -13,11 +13,6 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest
head :ok
end
- def set_deep_session_value
- session[:foo] = { bar: "baz" }
- head :ok
- end
-
def set_serialized_session_value
session[:foo] = SessionAutoloadTest::Foo.new
head :ok
@@ -27,14 +22,6 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest
render plain: "foo: #{session[:foo].inspect}"
end
- def get_deep_session_value_with_symbol
- render plain: "foo: { bar: #{session[:foo][:bar].inspect} }"
- end
-
- def get_deep_session_value_with_string
- render plain: "foo: { \"bar\" => #{session[:foo]["bar"].inspect} }"
- end
-
def get_session_id
render plain: "#{request.session.id}"
end
@@ -192,24 +179,6 @@ class MemCacheStoreTest < ActionDispatch::IntegrationTest
rescue Dalli::RingError => ex
skip ex.message, ex.backtrace
end
-
- def test_previous_session_has_indifferent_access
- with_test_route_set do
- get '/set_deep_session_value'
- assert_response :success
- assert cookies['_session_id']
-
- get '/get_deep_session_value_with_symbol'
- assert_response :success
- assert_equal 'foo: { bar: "baz" }', response.body
-
- get '/get_deep_session_value_with_string'
- assert_response :success
- assert_equal 'foo: { "bar" => "baz" }', response.body
- end
- rescue Dalli::RingError => ex
- skip ex.message, ex.backtrace
- end
rescue LoadError, RuntimeError, Dalli::DalliError
$stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again."
end
diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb
index 332c2ae3c8..3e61d123e3 100644
--- a/actionpack/test/dispatch/session/test_session_test.rb
+++ b/actionpack/test/dispatch/session/test_session_test.rb
@@ -60,11 +60,4 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase
session = ActionController::TestSession.new(one: '1')
assert_equal(2, session.fetch('2') { |key| key.to_i })
end
-
- def test_fetch_returns_indifferent_access
- session = ActionController::TestSession.new(three: { two: '1' })
- three = session.fetch(:three)
- assert_equal('1', three[:two])
- assert_equal('1', three["two"])
- end
end
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 8eb3b6190f..4431512eda 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -298,26 +298,30 @@ Open the file `config/routes.rb` in your editor.
Rails.application.routes.draw do
get 'welcome/index'
- # The priority is based upon order of creation:
- # first created -> highest priority.
- # See how all your routes lay out with "bin/rails routes".
- #
- # You can have the root of your site routed with "root"
- # root 'welcome#index'
- #
- # ...
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+
+ # Serve websocket cable requests in-process
+ # mount ActionCable.server => '/cable'
+end
```
This is your application's _routing file_ which holds entries in a special
[DSL (domain-specific language)](http://en.wikipedia.org/wiki/Domain-specific_language)
that tells Rails how to connect incoming requests to
-controllers and actions. This file contains many sample routes on commented
-lines, and one of them actually shows you how to connect the root of your site
-to a specific controller and action. Find the line beginning with `root` and
-uncomment it. It should look something like the following:
+controllers and actions.
+Edit this file by adding the line of code `root 'welcome#index'`.
+It should look something like the following:
```ruby
-root 'welcome#index'
+Rails.application.routes.draw do
+ get 'welcome/index'
+
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
+
+ # Serve websocket cable requests in-process
+ # mount ActionCable.server => '/cable'
+ root 'welcome#index'
+end
```
`root 'welcome#index'` tells Rails to map requests to the root of the
@@ -348,7 +352,7 @@ operations are referred to as _CRUD_ operations.
Rails provides a `resources` method which can be used to declare a standard REST
resource. You need to add the _article resource_ to the
-`config/routes.rb` as follows:
+`config/routes.rb` so the file will look as follows:
```ruby
Rails.application.routes.draw do
@@ -625,7 +629,7 @@ end
The `render` method here is taking a very simple hash with a key of `:plain` and
value of `params[:article].inspect`. The `params` method is the object which
represents the parameters (or fields) coming in from the form. The `params`
-method returns an `ActiveSupport::HashWithIndifferentAccess` object, which
+method returns an `ActionController::Parameters` object, which
allows you to access the keys of the hash using either strings or symbols. In
this situation, the only parameters that matter are the ones from the form.
@@ -635,7 +639,7 @@ If you re-submit the form one more time you'll now no longer get the missing
template error. Instead, you'll see something that looks like the following:
```ruby
-{"title"=>"First article!", "text"=>"This is my first article."}
+<ActionController::Parameters {"title"=>"First Article!", "text"=>"This is my first article."} permitted: false>
```
This action is now displaying the parameters for the article that are coming in