1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Add more tests for Utils.encode_query_string.

These tests, which follow the yard-doc examples, exercise the
new ParamsArray behavior.
This commit is contained in:
Andy Brody 2016-01-26 23:02:07 -05:00
parent 35b8b7336d
commit bad70fb1d8
2 changed files with 26 additions and 1 deletions

View file

@ -118,5 +118,30 @@ describe RestClient::Utils do
RestClient::Utils.encode_query_string(input).should eq expected
end
end
it 'handles deep nesting' do
{
{coords: [{x: 1, y: 0}, {x: 2}, {x: 3}]} => 'coords[][x]=1&coords[][y]=0&coords[][x]=2&coords[][x]=3',
}.each_pair do |input, expected|
RestClient::Utils.encode_query_string(input).should eq expected
end
end
it 'handles multiple fields with the same name using ParamsArray' do
{
RestClient::ParamsArray.new([[:foo, 1], [:foo, 2], [:foo, 3]]) => 'foo=1&foo=2&foo=3',
}.each_pair do |input, expected|
RestClient::Utils.encode_query_string(input).should eq expected
end
end
it 'handles nested ParamsArrays' do
{
{foo: RestClient::ParamsArray.new([[:a, 1], [:a, 2]])} => 'foo[a]=1&foo[a]=2',
RestClient::ParamsArray.new([[:foo, {a: 1}], [:foo, {a: 2}]]) => 'foo[a]=1&foo[a]=2',
}.each_pair do |input, expected|
RestClient::Utils.encode_query_string(input).should eq expected
end
end
end
end