diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-28 20:51:21 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-28 20:51:21 -0300 |
commit | 6924f848c45897004ba9cc4f96c032286dcce346 (patch) | |
tree | 9142119eaada73dbcb34d287b5d24f1cda92d6e0 /activesupport/test/core_ext/object | |
parent | 3ac731c4d0de940893f9dc486f6bebc9e3240f5a (diff) | |
parent | c420a8daf58cc1544a89ec1cec67005e1c654ad8 (diff) | |
download | rails-6924f848c45897004ba9cc4f96c032286dcce346.tar.gz rails-6924f848c45897004ba9cc4f96c032286dcce346.tar.bz2 rails-6924f848c45897004ba9cc4f96c032286dcce346.zip |
Merge pull request #15629 from akshay-vishnoi/test-to_param
Define Hash#to_query and set Hash#to_param as alias to it; with test cases
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 47220e9509..09cab3ed35 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -65,6 +65,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('&') |