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,6 +49,10 @@ describe Google::APIClient::Result do
'server' => 'GSE', 'server' => 'GSE',
'connection' => 'close' 'connection' => 'close'
}) })
end
describe 'with a next page token' do
before do
@response.stub(:body).and_return( @response.stub(:body).and_return(
<<-END_OF_STRING <<-END_OF_STRING
{ {
@ -78,5 +82,69 @@ describe Google::APIClient::Result do
path = reference.to_request.path.to_s path = reference.to_request.path.to_s
path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN' path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN'
end 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
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
end end