Adding batch support
[arvados.git] / spec / google / api_client / result_spec.rb
1 # Copyright 2012 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 require 'spec_helper'
16
17 require 'google/api_client'
18 require 'google/api_client/version'
19
20 describe Google::APIClient::Result do
21   before do
22     @client = Google::APIClient.new
23   end
24
25   describe 'with the plus API' do
26     before do
27       @client.authorization = nil
28       @plus = @client.discovered_api('plus', 'v1')
29       @reference = Google::APIClient::Reference.new({
30         :api_method => @plus.activities.list,
31         :parameters => {
32           'userId' => 'me',
33           'collection' => 'public',
34           'maxResults' => 20
35         }
36       })
37       @request = @reference.to_request
38
39       # Response stub
40       @response = stub("response")
41       @response.stub(:status).and_return(200)
42       @response.stub(:headers).and_return({
43         'etag' => '12345',
44         'x-google-apiary-auth-scopes' =>
45           'https://www.googleapis.com/auth/plus.me',
46         'content-type' => 'application/json; charset=UTF-8',
47         'date' => 'Mon, 23 Apr 2012 00:00:00 GMT',
48         'cache-control' => 'private, max-age=0, must-revalidate, no-transform',
49         'server' => 'GSE',
50         'connection' => 'close'
51       })
52       @response.stub(:body).and_return(
53         <<-END_OF_STRING
54         {
55           "kind": "plus#activityFeed",
56           "etag": "FOO",
57           "nextPageToken": "NEXT+PAGE+TOKEN",
58           "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?",
59           "nextLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN",
60           "title": "Plus Public Activity Feed for ",
61           "updated": "2012-04-23T00:00:00.000Z",
62           "id": "tag:google.com,2010:/plus/people/foo/activities/public",
63           "items": []
64         }
65         END_OF_STRING
66       )
67       @result = Google::APIClient::Result.new(@reference, @request, @response)
68     end
69
70     it 'should return the correct next page token' do
71       @result.next_page_token.should == 'NEXT+PAGE+TOKEN'
72     end
73
74     it 'should escape the next page token when calling next_page' do
75       reference = @result.next_page
76       reference.parameters.should include('pageToken')
77       reference.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN'
78       path = reference.to_request.path.to_s
79       path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN'
80     end
81   end
82 end