Skip to content

Commit

Permalink
Add more specs on params handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Apr 3, 2014
1 parent c89e109 commit 619b2d5
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions spec/http/client_spec.rb
Expand Up @@ -75,21 +75,43 @@ def simple_response(body, status = 200)

it 'accepts params within the provided URL' do
expect(HTTP::Request).to receive(:new) do |_, uri|
params = CGI.parse uri.query
expect(params).to eq('foo' => ['bar'])
expect(CGI.parse uri.query).to eq('foo' => %w[bar])
end

client.get('http://example.com/?foo=bar')
end

it 'combines GET params from the URI with the passed in params' do
expect(HTTP::Request).to receive(:new) do |_, uri|
params = CGI.parse uri.query
expect(params).to eq('foo' => ['bar'], 'baz' => ['quux'])
expect(CGI.parse uri.query).to eq('foo' => %w[bar], 'baz' => %w[quux])
end

client.get('http://example.com/?foo=bar', :params => {:baz => 'quux'})
end

it 'merges duplicate values' do
expect(HTTP::Request).to receive(:new) do |_, uri|
expect(CGI.parse uri.query).to eq('a' => %w[1 2])
end

client.get('http://example.com/?a=1', :params => {:a => 2})
end

it 'does not modifies query part if no params were given' do
expect(HTTP::Request).to receive(:new) do |_, uri|
expect(uri.query).to eq 'deadbeef'
end

client.get('http://example.com/?deadbeef')
end

it 'does not corrupts index-less arrays' do
expect(HTTP::Request).to receive(:new) do |_, uri|
expect(CGI.parse uri.query).to eq 'a[]' => %w[b c], 'd' => %w[e]
end

client.get('http://example.com/?a[]=b&a[]=c', :params => {:d => 'e'})
end
end

describe 'passing json' do
Expand Down

0 comments on commit 619b2d5

Please sign in to comment.