1 # Copyright 2012 Google Inc.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 require 'google/api_client'
18 require 'google/api_client/version'
20 describe Google::APIClient::Result do
22 @client = Google::APIClient.new
25 describe 'with the plus API' do
27 @client.authorization = nil
28 @plus = @client.discovered_api('plus', 'v1')
29 @reference = Google::APIClient::Reference.new({
30 :api_method => @plus.activities.list,
33 'collection' => 'public',
37 @request = @reference.to_request
40 @response = stub("response")
41 @response.stub(:status).and_return(200)
42 @response.stub(:headers).and_return({
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',
50 'connection' => 'close'
54 describe 'with a next page token' do
56 @response.stub(:body).and_return(
59 "kind": "plus#activityFeed",
61 "nextPageToken": "NEXT+PAGE+TOKEN",
62 "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?",
63 "nextLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN",
64 "title": "Plus Public Activity Feed for ",
65 "updated": "2012-04-23T00:00:00.000Z",
66 "id": "tag:google.com,2010:/plus/people/foo/activities/public",
71 @result = Google::APIClient::Result.new(@reference, @request, @response)
74 it 'should return the correct next page token' do
75 @result.next_page_token.should == 'NEXT+PAGE+TOKEN'
78 it 'should escape the next page token when calling next_page' do
79 reference = @result.next_page
80 reference.parameters.should include('pageToken')
81 reference.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN'
82 path = reference.to_request.path.to_s
83 path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN'
86 it 'should return content type correctly' do
87 @result.media_type.should == 'application/json'
90 it 'should return the result data correctly' do
91 @result.data?.should be_true
92 @result.data.class.to_s.should ==
93 'Google::APIClient::Schema::Plus::V1::ActivityFeed'
94 @result.data.kind.should == 'plus#activityFeed'
95 @result.data.etag.should == 'FOO'
96 @result.data.nextPageToken.should == 'NEXT+PAGE+TOKEN'
97 @result.data.selfLink.should ==
98 'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
99 @result.data.nextLink.should ==
100 'https://www.googleapis.com/plus/v1/people/foo/activities/public?' +
101 'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN'
102 @result.data.title.should == 'Plus Public Activity Feed for '
103 @result.data.id.should ==
104 'tag:google.com,2010:/plus/people/foo/activities/public'
105 @result.data.items.should be_empty
109 describe 'without a next page token' do
111 @response.stub(:body).and_return(
114 "kind": "plus#activityFeed",
116 "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?",
117 "title": "Plus Public Activity Feed for ",
118 "updated": "2012-04-23T00:00:00.000Z",
119 "id": "tag:google.com,2010:/plus/people/foo/activities/public",
124 @result = Google::APIClient::Result.new(@reference, @request, @response)
127 it 'should not return a next page token' do
128 @result.next_page_token.should == nil
131 it 'should return content type correctly' do
132 @result.media_type.should == 'application/json'
135 it 'should return the result data correctly' do
136 @result.data?.should be_true
137 @result.data.class.to_s.should ==
138 'Google::APIClient::Schema::Plus::V1::ActivityFeed'
139 @result.data.kind.should == 'plus#activityFeed'
140 @result.data.etag.should == 'FOO'
141 @result.data.selfLink.should ==
142 'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
143 @result.data.title.should == 'Plus Public Activity Feed for '
144 @result.data.id.should ==
145 'tag:google.com,2010:/plus/people/foo/activities/public'
146 @result.data.items.should be_empty