Accept repeated parameters
[arvados.git] / spec / google / api_client / discovery_spec.rb
index cd46068074d882a747f0b427df291e5799227b4e..7714e25c6052e9784e9803511a4a07a6249f51ba 100644 (file)
@@ -14,6 +14,7 @@
 
 require 'spec_helper'
 
+require 'json'
 require 'signet/oauth_1/client'
 require 'httpadapter/adapters/net_http'
 
@@ -76,6 +77,49 @@ describe Google::APIClient do
         'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
     end
 
+    it 'should correctly determine the discovery URI if :user_ip is set' do
+      @client.user_ip = '127.0.0.1'
+      request = @client.generate_request(
+        :http_method => 'GET',
+        :uri => @client.discovery_uri('prediction', 'v1.2'),
+        :authenticated => false
+      )
+      http_method, uri, headers, body = request
+      uri.should === (
+        'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
+        '?userIp=127.0.0.1'
+      )
+    end
+
+    it 'should correctly determine the discovery URI if :key is set' do
+      @client.key = 'qwerty'
+      request = @client.generate_request(
+        :http_method => 'GET',
+        :uri => @client.discovery_uri('prediction', 'v1.2'),
+        :authenticated => false
+      )
+      http_method, uri, headers, body = request
+      uri.should === (
+        'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
+        '?key=qwerty'
+      )
+    end
+
+    it 'should correctly determine the discovery URI if both are set' do
+      @client.key = 'qwerty'
+      @client.user_ip = '127.0.0.1'
+      request = @client.generate_request(
+        :http_method => 'GET',
+        :uri => @client.discovery_uri('prediction', 'v1.2'),
+        :authenticated => false
+      )
+      http_method, uri, headers, body = request
+      uri.should === (
+        'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
+        '?key=qwerty&userIp=127.0.0.1'
+      )
+    end
+
     it 'should correctly generate API objects' do
       @client.discovered_api('prediction', 'v1.2').name.should == 'prediction'
       @client.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
@@ -238,6 +282,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