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:
parent
35b8b7336d
commit
bad70fb1d8
2 changed files with 26 additions and 1 deletions
|
|
@ -154,7 +154,7 @@ module RestClient
|
|||
# => 'foo[string]=&foo[empty]'
|
||||
#
|
||||
# @example Multiple fields with the same name using ParamsArray
|
||||
# >> encode_query_string(RestClient::ParamsArray.new([[:foo, 1], [:foo, 2], [:foo, 3]])
|
||||
# >> encode_query_string(RestClient::ParamsArray.new([[:foo, 1], [:foo, 2], [:foo, 3]]))
|
||||
# => 'foo=1&foo=2&foo=3'
|
||||
#
|
||||
# @example Nested ParamsArray
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue