From c420a8daf58cc1544a89ec1cec67005e1c654ad8 Mon Sep 17 00:00:00 2001 From: Akshay Vishnoi Date: Fri, 20 Jun 2014 03:46:18 +0530 Subject: Move to_param to to_query, also Improve tests --- activesupport/test/core_ext/object/to_param_test.rb | 12 ++++++++++++ activesupport/test/core_ext/object/to_query_test.rb | 10 ++++++++++ 2 files changed, 22 insertions(+) (limited to 'activesupport/test/core_ext/object') 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('&') -- cgit v1.2.3