adds specs for storage
changes expectation in write_credentials
This commit is contained in:
parent
e6858bd292
commit
31fac0a6f5
|
@ -48,7 +48,7 @@ module Google
|
||||||
# already associated with this instance will be written.
|
# already associated with this instance will be written.
|
||||||
def write_credentials(authorization=nil)
|
def write_credentials(authorization=nil)
|
||||||
@authorization = authorization if authorization
|
@authorization = authorization if authorization
|
||||||
if @authorization.refresh_token
|
if @authorization.respond_to?(:refresh_token) && @authorization.refresh_token
|
||||||
store.write_credentials(credentials_hash)
|
store.write_credentials(credentials_hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,8 +40,8 @@ describe Google::APIClient::Storage do
|
||||||
subject.should_receive(:refresh_authorization)
|
subject.should_receive(:refresh_authorization)
|
||||||
subject.authorize
|
subject.authorize
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'without credentials' do
|
describe 'without credentials' do
|
||||||
|
|
||||||
it 'should return false' do
|
it 'should return false' do
|
||||||
|
@ -51,19 +51,34 @@ describe Google::APIClient::Storage do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'write_credentials' do
|
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 not call store to write credentials' do
|
||||||
|
subject.should_not_receive(:credentials_hash)
|
||||||
it 'should call store to write credentials'
|
subject.store.should_not_receive(:write_credentials)
|
||||||
|
expect {
|
||||||
it 'should not call store to write credentials'
|
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
|
end
|
||||||
|
|
||||||
describe 'refresh_authorization' do
|
describe 'refresh_authorization' do
|
||||||
|
|
||||||
it 'should call refresh and write credentials' do
|
it 'should call refresh and write credentials' do
|
||||||
subject.should_receive(:write_credentials)
|
subject.should_receive(:write_credentials)
|
||||||
authorization_stub = double
|
authorization_stub = double
|
||||||
|
@ -74,8 +89,31 @@ describe Google::APIClient::Storage do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'load_credentials' do
|
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
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue