Fixed issue with header/options ambiguity.
This commit is contained in:
parent
a281c1bcf5
commit
0d2cbe26df
|
@ -533,14 +533,10 @@ module Google
|
|||
# )
|
||||
def execute(*params)
|
||||
# This block of code allows us to accept multiple parameter passing
|
||||
# styles, and maintaining backwards compatibility.
|
||||
if params.last.respond_to?(:to_hash) && params.size != 2
|
||||
# Hash options are tricky. If we get two arguments, it's ambiguous
|
||||
# whether to treat them as API parameters or Hash options, but since
|
||||
# it's rare to need to pass in options, we must assume that the
|
||||
# developer wanted to pass API parameters. Prefer using named
|
||||
# parameters to avoid this issue. Unnamed parameters should be
|
||||
# considered syntactic sugar.
|
||||
# styles, and maintaining some backwards compatibility.
|
||||
#
|
||||
# Note: I'm extremely tempted to deprecate this style of execute call.
|
||||
if params.last.respond_to?(:to_hash) && params.size == 1
|
||||
options = params.pop
|
||||
else
|
||||
options = {}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
require 'spec_helper'
|
||||
|
||||
require 'json'
|
||||
require 'signet/oauth_1/client'
|
||||
require 'httpadapter/adapters/net_http'
|
||||
|
||||
|
@ -238,6 +239,19 @@ describe Google::APIClient do
|
|||
)
|
||||
end).should raise_error(Google::APIClient::ClientError)
|
||||
end
|
||||
|
||||
it 'should correctly handle unnamed parameters' do
|
||||
@client.authorization = :oauth_2
|
||||
@client.authorization.access_token = '12345'
|
||||
result = @client.execute(
|
||||
@prediction.training.insert,
|
||||
{},
|
||||
JSON.generate({"id" => "bucket/object"}),
|
||||
{'Content-Type' => 'application/json'}
|
||||
)
|
||||
method, uri, headers, body = result.request
|
||||
Hash[headers]['Content-Type'].should == 'application/json'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with the buzz API' do
|
||||
|
|
Loading…
Reference in New Issue