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