Added some more specs for Google::APIClient::Result

This commit is contained in:
Sergio Gomes 2012-05-16 20:26:10 +01:00
parent a666d52770
commit 574cdbd739
1 changed files with 92 additions and 24 deletions

View File

@ -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