aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-02 05:32:44 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-02 05:32:44 +0000
commit9e1d91c24bfd260df8609d5008fe40210f32cfd9 (patch)
treefe35167ca8cc78b67470ef50f3111fc14ab76651
parentfbd3eb7142e2ac51b230ab2fff83feb800e1b50c (diff)
downloadrails-9e1d91c24bfd260df8609d5008fe40210f32cfd9.tar.gz
rails-9e1d91c24bfd260df8609d5008fe40210f32cfd9.tar.bz2
rails-9e1d91c24bfd260df8609d5008fe40210f32cfd9.zip
TestSession supports indifferent access. Closes #7372.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8782 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/test_process.rb6
-rw-r--r--actionpack/test/controller/test_test.rb26
3 files changed, 31 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 3cf0abc6c7..2e990c5b9b 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* TestSession supports indifferent access. #7372 [tamc, Arsen7, mhackett, julik, jean.helou]
+
* Make assert_routing aware of the HTTP method used. #8039 [mpalmer]
e.g. assert_routing({ :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" })
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index ba23f012da..f8af3ccaf2 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -287,7 +287,7 @@ module ActionController #:nodoc:
def initialize(attributes = nil)
@session_id = ''
- @attributes = attributes
+ @attributes = attributes.nil? ? nil : attributes.stringify_keys
@saved_attributes = nil
end
@@ -296,11 +296,11 @@ module ActionController #:nodoc:
end
def [](key)
- data[key]
+ data[key.to_s]
end
def []=(key, value)
- data[key] = value
+ data[key.to_s] = value
end
def update
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 806fe32cd4..7755fb7405 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -3,11 +3,21 @@ require 'controller/fake_controllers'
class TestTest < Test::Unit::TestCase
class TestController < ActionController::Base
+ def no_op
+ render :text => 'dummy'
+ end
+
def set_flash
flash["test"] = ">#{flash["test"]}<"
render :text => 'ignore me'
end
+ def set_session
+ session['string'] = 'A wonder'
+ session[:symbol] = 'it works'
+ render :text => 'Success'
+ end
+
def render_raw_post
raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank?
render :text => request.raw_post
@@ -135,6 +145,22 @@ XML
assert_equal '>value<', flash['test']
end
+ def test_process_with_session
+ process :set_session
+ assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key"
+ assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access"
+ assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access"
+ assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access"
+ end
+
+ def test_process_with_session_arg
+ process :no_op, nil, { 'string' => 'value1', :symbol => 'value2' }
+ assert_equal 'value1', session['string']
+ assert_equal 'value1', session[:string]
+ assert_equal 'value2', session['symbol']
+ assert_equal 'value2', session[:symbol]
+ end
+
def test_process_with_request_uri_with_no_params
process :test_uri
assert_equal "/test_test/test/test_uri", @response.body