From 574cdbd739e9ff29aead16322fe4876993ad4fbb Mon Sep 17 00:00:00 2001 From: Sergio Gomes Date: Wed, 16 May 2012 20:26:10 +0100 Subject: [PATCH] Added some more specs for Google::APIClient::Result --- spec/google/api_client/result_spec.rb | 116 ++++++++++++++++++++------ 1 file changed, 92 insertions(+), 24 deletions(-) diff --git a/spec/google/api_client/result_spec.rb b/spec/google/api_client/result_spec.rb index 8dd2f82eb..50d0a7131 100644 --- a/spec/google/api_client/result_spec.rb +++ b/spec/google/api_client/result_spec.rb @@ -49,34 +49,102 @@ describe Google::APIClient::Result do 'server' => 'GSE', 'connection' => 'close' }) - @response.stub(:body).and_return( - <<-END_OF_STRING - { - "kind": "plus#activityFeed", - "etag": "FOO", - "nextPageToken": "NEXT+PAGE+TOKEN", - "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?", - "nextLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN", - "title": "Plus Public Activity Feed for ", - "updated": "2012-04-23T00:00:00.000Z", - "id": "tag:google.com,2010:/plus/people/foo/activities/public", - "items": [] - } - END_OF_STRING - ) - @result = Google::APIClient::Result.new(@reference, @request, @response) end - it 'should return the correct next page token' do - @result.next_page_token.should == 'NEXT+PAGE+TOKEN' + describe 'with a next page token' do + before do + @response.stub(:body).and_return( + <<-END_OF_STRING + { + "kind": "plus#activityFeed", + "etag": "FOO", + "nextPageToken": "NEXT+PAGE+TOKEN", + "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?", + "nextLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN", + "title": "Plus Public Activity Feed for ", + "updated": "2012-04-23T00:00:00.000Z", + "id": "tag:google.com,2010:/plus/people/foo/activities/public", + "items": [] + } + END_OF_STRING + ) + @result = Google::APIClient::Result.new(@reference, @request, @response) + end + + it 'should return the correct next page token' do + @result.next_page_token.should == 'NEXT+PAGE+TOKEN' + end + + it 'should escape the next page token when calling next_page' do + reference = @result.next_page + reference.parameters.should include('pageToken') + reference.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN' + path = reference.to_request.path.to_s + path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN' + end + + it 'should return content type correctly' do + @result.media_type.should == 'application/json' + end + + it 'should return the result data correctly' do + @result.data?.should be_true + @result.data.class.to_s.should == + 'Google::APIClient::Schema::Plus::V1::ActivityFeed' + @result.data.kind.should == 'plus#activityFeed' + @result.data.etag.should == 'FOO' + @result.data.nextPageToken.should == 'NEXT+PAGE+TOKEN' + @result.data.selfLink.should == + 'https://www.googleapis.com/plus/v1/people/foo/activities/public?' + @result.data.nextLink.should == + 'https://www.googleapis.com/plus/v1/people/foo/activities/public?' + + 'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN' + @result.data.title.should == 'Plus Public Activity Feed for ' + @result.data.id.should == + 'tag:google.com,2010:/plus/people/foo/activities/public' + @result.data.items.should be_empty + end end - it 'should escape the next page token when calling next_page' do - reference = @result.next_page - reference.parameters.should include('pageToken') - reference.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN' - path = reference.to_request.path.to_s - path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN' + describe 'without a next page token' do + before do + @response.stub(:body).and_return( + <<-END_OF_STRING + { + "kind": "plus#activityFeed", + "etag": "FOO", + "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?", + "title": "Plus Public Activity Feed for ", + "updated": "2012-04-23T00:00:00.000Z", + "id": "tag:google.com,2010:/plus/people/foo/activities/public", + "items": [] + } + END_OF_STRING + ) + @result = Google::APIClient::Result.new(@reference, @request, @response) + end + + it 'should not return a next page token' do + @result.next_page_token.should == nil + end + + it 'should return content type correctly' do + @result.media_type.should == 'application/json' + end + + it 'should return the result data correctly' do + @result.data?.should be_true + @result.data.class.to_s.should == + 'Google::APIClient::Schema::Plus::V1::ActivityFeed' + @result.data.kind.should == 'plus#activityFeed' + @result.data.etag.should == 'FOO' + @result.data.selfLink.should == + 'https://www.googleapis.com/plus/v1/people/foo/activities/public?' + @result.data.title.should == 'Plus Public Activity Feed for ' + @result.data.id.should == + 'tag:google.com,2010:/plus/people/foo/activities/public' + @result.data.items.should be_empty + end end end end