diff options
author | Akshay Vishnoi <akshay.vishnoi@vinsol.com> | 2014-06-20 03:46:18 +0530 |
---|---|---|
committer | Akshay Vishnoi <akshay.vishnoi@vinsol.com> | 2014-06-20 03:46:18 +0530 |
commit | c420a8daf58cc1544a89ec1cec67005e1c654ad8 (patch) | |
tree | efc4ff882c827ca3af4e21cd1c6f73211c8a6d61 /activesupport/test/core_ext/object | |
parent | 3681e1ac2c5448b9826f2e3c9b6508c50d2b4f17 (diff) | |
download | rails-c420a8daf58cc1544a89ec1cec67005e1c654ad8.tar.gz rails-c420a8daf58cc1544a89ec1cec67005e1c654ad8.tar.bz2 rails-c420a8daf58cc1544a89ec1cec67005e1c654ad8.zip |
Move to_param to to_query, also Improve tests
Diffstat (limited to 'activesupport/test/core_ext/object')
-rw-r--r-- | activesupport/test/core_ext/object/to_param_test.rb | 12 | ||||
-rw-r--r-- | activesupport/test/core_ext/object/to_query_test.rb | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/object/to_param_test.rb b/activesupport/test/core_ext/object/to_param_test.rb index bd7c6c422a..25c3bf22c3 100644 --- a/activesupport/test/core_ext/object/to_param_test.rb +++ b/activesupport/test/core_ext/object/to_param_test.rb @@ -16,4 +16,16 @@ class ToParamTest < ActiveSupport::TestCase assert_equal true, true.to_param assert_equal false, false.to_param end + + def test_array + # Empty Array + assert_equal '', [].to_param + + array = [1, 2, 3, 4] + assert_equal "1/2/3/4", array.to_param + + # Array of different objects + array = [1, '3', { a: 1, b: 2 }, nil, true, false] + assert_equal "1/3/a=1&b=2//true/false", array.to_param + end end diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 7457c4655a..3c69e3440e 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -61,6 +61,16 @@ class ToQueryTest < ActiveSupport::TestCase {a: [], b: 3} end + def test_hash_with_namespace + hash = { name: 'Nakshay', nationality: 'Indian' } + assert_equal "user%5Bname%5D=Nakshay&user%5Bnationality%5D=Indian", hash.to_query('user') + end + + def test_hash_sorted_lexicographically + hash = { type: 'human', name: 'Nakshay' } + assert_equal "name=Nakshay&type=human", hash.to_query + end + private def assert_query_equal(expected, actual) assert_equal expected.split('&'), actual.to_query.split('&') |