aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-02-11 06:29:04 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-02-11 06:29:04 +0000
commit002c0aeef3302d6cceecfd039a325e0eef59c17a (patch)
tree5481e87590fb537d15c66c76da67d43e800ae135 /activesupport/test/core_ext
parent39ae7025e84e35785e11d9fed059e74e70745ee3 (diff)
downloadrails-002c0aeef3302d6cceecfd039a325e0eef59c17a.tar.gz
rails-002c0aeef3302d6cceecfd039a325e0eef59c17a.tar.bz2
rails-002c0aeef3302d6cceecfd039a325e0eef59c17a.zip
Hash#to_query CGI-escapes its keys.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6148 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb30
1 files changed, 22 insertions, 8 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 2946e849e0..8a120fdfee 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -530,22 +530,36 @@ end
class QueryTest < Test::Unit::TestCase
def test_simple_conversion
- assert_equal 'a=10', {:a => 10}.to_query
+ assert_query_equal 'a=10', :a => 10
+ end
+
+ def test_cgi_escaping
+ assert_query_equal 'a%3Ab=c+d', 'a:b' => 'c d'
+ end
+
+ def test_nil_parameter_value
+ empty = Object.new
+ def empty.to_param; nil end
+ assert_query_equal 'a=', 'a' => empty
end
def test_nested_conversion
- expected = %w(person[name]=Nicholas person[login]=seckar)
- actual = {:person => {:name => 'Nicholas', :login => 'seckar'}}.to_query
- assert_equal expected.sort, actual.split('&').sort
+ assert_query_equal 'person%5Bname%5D=Nicholas&person%5Blogin%5D=seckar',
+ :person => {:name => 'Nicholas', :login => 'seckar'}
end
def test_multiple_nested
- assert_equal 'account[person][id]=20&person[id]=10',
- {:person => {:id => 10}, :account => {:person => {:id => 20}}}.to_query
+ assert_query_equal 'account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10',
+ :person => {:id => 10}, :account => {:person => {:id => 20}}
end
def test_array_values
- assert_equal 'person[id][]=10&person[id][]=20',
- {:person => {:id => [10, 20]}}.to_query
+ assert_query_equal 'person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20',
+ :person => {:id => [10, 20]}
end
+
+ private
+ def assert_query_equal(expected, actual, message = nil)
+ assert_equal expected.split('&').sort, actual.to_query.split('&').sort
+ end
end