|
7 | 7 | let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..')) }
|
8 | 8 | let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
|
9 | 9 |
|
| 10 | + let(:store) { double } |
| 11 | + let(:client_stub) { double } |
| 12 | + subject { Google::APIClient::Storage.new(store) } |
| 13 | + |
10 | 14 | it 'should initialize'
|
11 | 15 |
|
12 | 16 | 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 |
14 | 52 | end
|
15 | 53 |
|
16 | 54 |
|
|
26 | 64 |
|
27 | 65 | describe 'refresh_authorization' do
|
28 | 66 |
|
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 |
31 | 74 | end
|
32 | 75 |
|
33 | 76 | describe 'load_credentials' do
|
|
0 commit comments