Skip to content

Commit 31fac0a

Browse files
committed
adds specs for storage
changes expectation in write_credentials
1 parent e6858bd commit 31fac0a

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

lib/google/api_client/auth/storage.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def initialize(store)
4848
# already associated with this instance will be written.
4949
def write_credentials(authorization=nil)
5050
@authorization = authorization if authorization
51-
if @authorization.refresh_token
51+
if @authorization.respond_to?(:refresh_token) && @authorization.refresh_token
5252
store.write_credentials(credentials_hash)
5353
end
5454
end

spec/google/api_client/auth/storage_spec.rb

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
subject.should_receive(:refresh_authorization)
4141
subject.authorize
4242
end
43-
4443
end
44+
4545
describe 'without credentials' do
4646

4747
it 'should return false' do
@@ -51,19 +51,34 @@
5151
end
5252
end
5353

54-
5554
describe 'write_credentials' do
55+
it 'should call store to write credentials' do
56+
authorization_stub = double
57+
authorization_stub.should_receive(:refresh_token).and_return(true)
58+
subject.should_receive(:credentials_hash)
59+
subject.store.should_receive(:write_credentials)
60+
subject.write_credentials(authorization_stub)
61+
subject.authorization.should == authorization_stub
62+
end
5663

57-
it 'should store credentials to var'
58-
59-
it 'should call store to write credentials'
60-
61-
it 'should not call store to write credentials'
64+
it 'should not call store to write credentials' do
65+
subject.should_not_receive(:credentials_hash)
66+
subject.store.should_not_receive(:write_credentials)
67+
expect {
68+
subject.write_credentials()
69+
}.not_to raise_error
70+
end
71+
it 'should not call store to write credentials' do
72+
subject.should_not_receive(:credentials_hash)
73+
subject.store.should_not_receive(:write_credentials)
74+
expect {
75+
subject.write_credentials('something')
76+
}.not_to raise_error
77+
end
6278

6379
end
6480

6581
describe 'refresh_authorization' do
66-
6782
it 'should call refresh and write credentials' do
6883
subject.should_receive(:write_credentials)
6984
authorization_stub = double
@@ -74,8 +89,31 @@
7489
end
7590

7691
describe 'load_credentials' do
77-
it 'should call store to load credentials'
78-
92+
it 'should call store to load credentials' do
93+
subject.store.should_receive(:load_credentials)
94+
subject.send(:load_credentials)
95+
end
7996
end
8097

98+
describe 'credentials_hash' do
99+
it 'should return an hash' do
100+
authorization_stub = double
101+
authorization_stub.should_receive(:access_token)
102+
authorization_stub.should_receive(:client_id)
103+
authorization_stub.should_receive(:client_secret)
104+
authorization_stub.should_receive(:expires_in)
105+
authorization_stub.should_receive(:refresh_token)
106+
authorization_stub.should_receive(:issued_at).and_return('100')
107+
subject.stub(:authorization).and_return(authorization_stub)
108+
credentials = subject.send(:credentials_hash)
109+
credentials.should include(:access_token)
110+
credentials.should include(:authorization_uri)
111+
credentials.should include(:client_id)
112+
credentials.should include(:client_secret)
113+
credentials.should include(:expires_in)
114+
credentials.should include(:refresh_token)
115+
credentials.should include(:token_credential_uri)
116+
credentials.should include(:issued_at)
117+
end
118+
end
81119
end

0 commit comments

Comments
 (0)