|
2 | 2 | require_relative '../../../../../lib/google/api_client/auth/storages/redis_store'
|
3 | 3 |
|
4 | 4 | describe Google::APIClient::RedisStore do
|
| 5 | + let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..', '..', '..')) } |
5 | 6 | let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
|
| 7 | + let(:redis) {double} |
6 | 8 |
|
7 |
| - it 'should initialize' |
| 9 | + let(:credentials_hash) { { |
| 10 | + "access_token" => "my_access_token", |
| 11 | + "authorization_uri" => "https://accounts.google.com/o/oauth2/auth", |
| 12 | + "client_id" => "[email protected]", |
| 13 | + "client_secret" => "123456_client_secret", |
| 14 | + "expires_in" => 3600, |
| 15 | + "refresh_token" => "my_refresh_token", |
| 16 | + "token_credential_uri" => "https://accounts.google.com/o/oauth2/token", |
| 17 | + "issued_at" => 1384440275 |
| 18 | + } } |
8 | 19 |
|
9 |
| - it 'should load credentials' |
| 20 | + subject { Google::APIClient::RedisStore.new('a redis instance') } |
10 | 21 |
|
11 |
| - it 'should write credentials' |
| 22 | + it 'should have a redis instance' do |
| 23 | + subject.redis.should == 'a redis instance' |
| 24 | + subject.redis = 'an other redis instance' |
| 25 | + subject.redis.should == 'an other redis instance' |
| 26 | + end |
| 27 | + |
| 28 | + describe 'load_credentials' do |
| 29 | + |
| 30 | + it 'should load credentials' do |
| 31 | + subject.redis= redis |
| 32 | + redis.should_receive(:get).and_return(credentials_hash.to_json) |
| 33 | + subject.load_credentials.should == credentials_hash |
| 34 | + end |
| 35 | + |
| 36 | + it 'should return nil' do |
| 37 | + subject.redis= redis |
| 38 | + redis.should_receive(:get).and_return(nil) |
| 39 | + subject.load_credentials.should == nil |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe 'write credentials' do |
| 44 | + |
| 45 | + it 'should write credentials' do |
| 46 | + subject.redis= redis |
| 47 | + redis.should_receive(:set).and_return('ok') |
| 48 | + subject.write_credentials(credentials_hash).should be_true |
| 49 | + end |
| 50 | + end |
12 | 51 |
|
13 | 52 | end
|
0 commit comments