Upgrade to Faraday 0.9 (fixes params encoding problems)

This commit is contained in:
Steven Bazyl committed 2013-05-13 14:03:49 -07:00
1 parent 9cd5601134
commit 794c6a90f7
11 files changed
+53 -49

No files matched your search

+1 -1
View File
@@ -234,7 +234,7 @@ describe Google::APIClient::BatchRequest do
it 'should convert to a correct HTTP request' do
batch = Google::APIClient::BatchRequest.new { |result| }
batch.add(@call1, '1').add(@call2, '2')
request = batch.to_env(Faraday.default_connection)
request = batch.to_env(CLIENT.connection)
boundary = Google::APIClient::BatchRequest::BATCH_BOUNDARY
request[:method].to_s.downcase.should == 'post'
request[:url].to_s.should == 'https://www.googleapis.com/batch'
+10 -24
View File
@@ -25,22 +25,6 @@ require 'signet/oauth_1/client'
require 'google/api_client'
require 'google/api_client/version'
def TestHandler
def initialize(&block)
@block = block
end
def call(env)
@block.call(env)
end
end
def mock_connection(&block)
connection = Faraday.new do |builder|
use TestHandler block
end
end
describe Google::APIClient do
include ConnectionHelpers
CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
@@ -231,16 +215,18 @@ describe Google::APIClient do
conn.verify
end
it 'should generate valid requests when repeated parameters are passed' do
pending("This is caused by Faraday's encoding of query parameters.")
it 'should generate valid requests when multivalued parameters are passed' do
conn = stub_connection do |stub|
stub.post('/prediction/v1.2/training?data=1&data=2') do |env|
env[:params]['data'].should include('1', '2')
# Test is now passing with Faraday 0.9.0.rc1, but small bug in test adapter
#params = env[:params]
params = Faraday::FlatParamsEncoder.decode(env.url.query)
params['data'].should include('1', '2')
end
end
request = CLIENT.execute(
:api_method => @prediction.training.insert,
:parameters => [['data', '1'], ['data','2']],
:parameters => {'data' => ['1', '2']},
:connection => conn
)
conn.verify
@@ -465,7 +451,7 @@ describe Google::APIClient do
'userId' => '107807692475771887386', 'collection' => 'bogus'
},
:authenticated => false
).to_env(Faraday.default_connection)
).to_env(CLIENT.connection)
end).should raise_error(ArgumentError)
end
end
@@ -511,7 +497,7 @@ describe Google::APIClient do
:api_method => @latitude.current_location.get,
:authenticated => false
)
request.to_env(Faraday.default_connection)[:url].to_s.should ===
request.to_env(CLIENT.connection)[:url].to_s.should ===
'https://www.googleapis.com/latitude/v1/currentLocation'
end
@@ -520,7 +506,7 @@ describe Google::APIClient do
:api_method => @latitude.current_location.get,
:authenticated => false
)
request.to_env(Faraday.default_connection)[:url].to_s.should ===
request.to_env(CLIENT.connection)[:url].to_s.should ===
'https://www.googleapis.com/latitude/v1/currentLocation'
end
@@ -630,7 +616,7 @@ describe Google::APIClient do
end
it 'should succeed when validating repeated parameters in a correct call' do
pending("This is caused by Faraday's encoding of query parameters.")
# pending("This is caused by Faraday's encoding of query parameters.")
conn = stub_connection do |stub|
stub.get('/adsense/v1/reports?dimension=DATE&dimension=PRODUCT_CODE'+
'&endDate=2010-01-01&metric=CLICKS&metric=PAGE_VIEWS&'+
+1 -2
View File
@@ -78,11 +78,10 @@ describe Google::APIClient::Result do
end
it 'should escape the next page token when calling next_page' do
pending("This is caused by Faraday's encoding of query parameters.")
reference = @result.next_page
Hash[reference.parameters].should include('pageToken')
Hash[reference.parameters]['pageToken'].should == 'NEXT+PAGE+TOKEN'
url = reference.to_env(Faraday.default_connection)[:url]
url = reference.to_env(CLIENT.connection)[:url]
url.to_s.should include('pageToken=NEXT%2BPAGE%2BTOKEN')
end
+3
View File
@@ -4,6 +4,8 @@ $LOAD_PATH.uniq!
require 'rspec'
require 'faraday'
Faraday::Adapter.load_middleware(:test)
module Faraday
class Connection
def verify
@@ -22,6 +24,7 @@ module ConnectionHelpers
block.call(stub)
end
connection = Faraday.new do |builder|
builder.options.params_encoder = Faraday::FlatParamsEncoder
builder.adapter(:test, stubs)
end
end