Skip to content

Commit

Permalink
Array#to_query preserves its ordering. References #7756.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6378 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Mar 11, 2007
1 parent 3edc98a commit 8a7275e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Array#to_query preserves its ordering. #7756 [Greg Spurrier]

* Out-of-range Time calculations transparently overflow to DateTime. Introduce Time#to_datetime. #7706, #7715 [Geoff Buesing]

* DateTime calculations analogous to the Date and Time extensions. #7693 [Geoff Buesing]
Expand Down
Expand Up @@ -15,7 +15,7 @@ def to_query(key) #:nodoc:

class Array
def to_query(key) #:nodoc:
collect { |value| value.to_query("#{key}[]") }.sort * '&'
collect { |value| value.to_query("#{key}[]") } * '&'
end
end

Expand Down
9 changes: 7 additions & 2 deletions activesupport/test/core_ext/hash_ext_test.rb
Expand Up @@ -544,7 +544,7 @@ def empty.to_param; nil end
end

def test_nested_conversion
assert_query_equal 'person%5Bname%5D=Nicholas&person%5Blogin%5D=seckar',
assert_query_equal 'person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas',
:person => {:name => 'Nicholas', :login => 'seckar'}
end

Expand All @@ -558,8 +558,13 @@ def test_array_values
:person => {:id => [10, 20]}
end

def test_array_values_are_not_sorted
assert_query_equal 'person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10',
:person => {:id => [20, 10]}
end

private
def assert_query_equal(expected, actual, message = nil)
assert_equal expected.split('&').sort, actual.to_query.split('&').sort
assert_equal expected.split('&'), actual.to_query.split('&')
end
end

0 comments on commit 8a7275e

Please sign in to comment.