Skip to content

Commit e6858bd

Browse files
committed
adds some specs for storage class
1 parent 6404615 commit e6858bd

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

spec/google/api_client/auth/storage_spec.rb

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,48 @@
77
let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..')) }
88
let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
99

10+
let(:store) { double }
11+
let(:client_stub) { double }
12+
subject { Google::APIClient::Storage.new(store) }
13+
1014
it 'should initialize'
1115

1216
describe 'authorize' do
13-
it 'should authorize'
17+
it 'should authorize' do
18+
subject.should respond_to(:authorization)
19+
subject.store.should == store
20+
end
21+
end
22+
23+
describe 'authorize' do
24+
describe 'with credentials' do
25+
26+
it 'should initialize a new OAuth Client' do
27+
subject.should_receive(:load_credentials).and_return({:first => 'a dummy'})
28+
client_stub.stub(:issued_at=)
29+
client_stub.stub(:expired?).and_return(false)
30+
Signet::OAuth2::Client.should_receive(:new).and_return(client_stub)
31+
subject.should_not_receive(:refresh_authorization)
32+
subject.authorize
33+
end
34+
35+
it 'should refresh authorization' do
36+
subject.should_receive(:load_credentials).and_return({:first => 'a dummy'})
37+
client_stub.stub(:issued_at=)
38+
client_stub.stub(:expired?).and_return(true)
39+
Signet::OAuth2::Client.should_receive(:new).and_return(client_stub)
40+
subject.should_receive(:refresh_authorization)
41+
subject.authorize
42+
end
43+
44+
end
45+
describe 'without credentials' do
46+
47+
it 'should return false' do
48+
subject.should_receive(:load_credentials).and_return({})
49+
subject.authorize.should be_false
50+
end
51+
end
1452
end
1553

1654

@@ -26,8 +64,13 @@
2664

2765
describe 'refresh_authorization' do
2866

29-
it 'should call refresh and write credentials'
30-
67+
it 'should call refresh and write credentials' do
68+
subject.should_receive(:write_credentials)
69+
authorization_stub = double
70+
subject.stub(:authorization).and_return(authorization_stub)
71+
authorization_stub.should_receive(:refresh!).and_return(true)
72+
subject.refresh_authorization
73+
end
3174
end
3275

3376
describe 'load_credentials' do

0 commit comments

Comments
 (0)