mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
3d0fd0b188
If there is already a '?' in the URL, add additional query params using '&' instead. Ideally we would be more clever about this and actually take the URL into parts and then unparse in a structured way rather than just blindly appending, but oh well. Fixes: #402, #96
40 lines
2.2 KiB
Ruby
40 lines
2.2 KiB
Ruby
require_relative '_lib'
|
|
|
|
describe RestClient::Request do
|
|
|
|
context 'params for GET requests' do
|
|
it "manage params for get requests" do
|
|
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should eq 'foo'
|
|
|
|
stub_request(:get, 'http://some/resource').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should eq 'foo'
|
|
end
|
|
|
|
it 'adds GET params when params are present in URL' do
|
|
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
|
RestClient::Request.execute(:url => 'http://some/resource?a=b', :method => :get, :headers => {:foo => :bar, :params => {:c => 'd'}}).body.should eq 'foo'
|
|
end
|
|
|
|
end
|
|
|
|
it "can use a block to process response" do
|
|
response_value = nil
|
|
block = proc do |http_response|
|
|
response_value = http_response.body
|
|
end
|
|
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}, :block_response => block)
|
|
response_value.should eq "foo"
|
|
end
|
|
|
|
it 'closes payload if not nil' do
|
|
test_file = File.new(File.join( File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))
|
|
|
|
stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
|
RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
|
|
|
|
test_file.closed?.should be true
|
|
end
|
|
|
|
end
|