adds specs for storage

changes expectation in write_credentials
This commit is contained in:
Volker Zöpfel 2013-11-28 08:14:41 +01:00
parent e6858bd292
commit 31fac0a6f5
2 changed files with 49 additions and 11 deletions

View File

@ -48,7 +48,7 @@ module Google
# already associated with this instance will be written.
def write_credentials(authorization=nil)
@authorization = authorization if authorization
if @authorization.refresh_token
if @authorization.respond_to?(:refresh_token) && @authorization.refresh_token
store.write_credentials(credentials_hash)
end
end

View File

@ -40,8 +40,8 @@ describe Google::APIClient::Storage do
subject.should_receive(:refresh_authorization)
subject.authorize
end
end
describe 'without credentials' do
it 'should return false' do
@ -51,19 +51,34 @@ describe Google::APIClient::Storage do
end
end
describe 'write_credentials' do
it 'should call store to write credentials' do
authorization_stub = double
authorization_stub.should_receive(:refresh_token).and_return(true)
subject.should_receive(:credentials_hash)
subject.store.should_receive(:write_credentials)
subject.write_credentials(authorization_stub)
subject.authorization.should == authorization_stub
end
it 'should store credentials to var'
it 'should call store to write credentials'
it 'should not call store to write credentials'
it 'should not call store to write credentials' do
subject.should_not_receive(:credentials_hash)
subject.store.should_not_receive(:write_credentials)
expect {
subject.write_credentials()
}.not_to raise_error
end
it 'should not call store to write credentials' do
subject.should_not_receive(:credentials_hash)
subject.store.should_not_receive(:write_credentials)
expect {
subject.write_credentials('something')
}.not_to raise_error
end
end
describe 'refresh_authorization' do
it 'should call refresh and write credentials' do
subject.should_receive(:write_credentials)
authorization_stub = double
@ -74,8 +89,31 @@ describe Google::APIClient::Storage do
end
describe 'load_credentials' do
it 'should call store to load credentials'
it 'should call store to load credentials' do
subject.store.should_receive(:load_credentials)
subject.send(:load_credentials)
end
end
describe 'credentials_hash' do
it 'should return an hash' do
authorization_stub = double
authorization_stub.should_receive(:access_token)
authorization_stub.should_receive(:client_id)
authorization_stub.should_receive(:client_secret)
authorization_stub.should_receive(:expires_in)
authorization_stub.should_receive(:refresh_token)
authorization_stub.should_receive(:issued_at).and_return('100')
subject.stub(:authorization).and_return(authorization_stub)
credentials = subject.send(:credentials_hash)
credentials.should include(:access_token)
credentials.should include(:authorization_uri)
credentials.should include(:client_id)
credentials.should include(:client_secret)
credentials.should include(:expires_in)
credentials.should include(:refresh_token)
credentials.should include(:token_credential_uri)
credentials.should include(:issued_at)
end
end
end