Permalink
Browse files

Sorting query parameters by key before processing

 - Query parameter order in specs to use sorted values again
 - Adding test for maintained array value order
 - Updating test to include mix of array and non-array values for sort.
  • Loading branch information...
1 parent 615f9b2 commit ac468e0425ce77bec35b6bd6c87422c229daeda6 @Billiam Billiam committed Oct 21, 2013
Showing with 5 additions and 5 deletions.
  1. +1 −1 lib/httparty/request.rb
  2. +4 −4 spec/httparty/request_spec.rb
View
@@ -15,7 +15,7 @@ class Request #:nodoc:
SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic]
NON_RAILS_QUERY_STRING_NORMALIZER = Proc.new do |query|
- Array(query).map do |key, value|
+ Array(query).sort_by { |a| a[0].to_s }.map do |key, value|
if value.nil?
key.to_s
elsif value.is_a?(Array)
@@ -17,12 +17,12 @@
it "doesn't include brackets" do
query_string = normalizer[{:page => 1, :foo => %w(bar baz)}]
- URI.unescape(query_string).should == "page=1&foo=bar&foo=baz"
+ URI.unescape(query_string).should == "foo=bar&foo=baz&page=1"
end
it "URI encodes array values" do
- query_string = normalizer[{:people => ["Bob Marley", "Tim & Jon"]}]
- query_string.should == "people=Bob%20Marley&people=Tim%20%26%20Jon"
+ query_string = normalizer[{:people => ["Otis Redding", "Bob Marley", "Tim & Jon"], :page => 1, :xyzzy => 3}]
+ query_string.should == "page=1&people=Otis%20Redding&people=Bob%20Marley&people=Tim%20%26%20Jon&xyzzy=3"
end
end
@@ -156,7 +156,7 @@
@request.options[:body] = {:page => 1, :foo => %w(bar baz)}
@request.send(:setup_raw_request)
body = @request.instance_variable_get(:@raw_request).body
- URI.unescape(body).should == "page=1&foo=bar&foo=baz"
+ URI.unescape(body).should == "foo=bar&foo=baz&page=1"
end
end
end

0 comments on commit ac468e0

Please sign in to comment.