3 require 'google/api_client'
4 require 'google/api_client/version'
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')) }
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",
18 "refresh_token" => "my_refresh_token",
19 "token_credential_uri" => "https://accounts.google.com/o/oauth2/token",
20 "issued_at" => 1384440275
23 subject { Google::APIClient::RedisStore.new('a redis instance') }
25 it 'should have a redis instance' do
26 expect(subject.redis).to be == 'a redis instance'
27 subject.redis = 'an other redis instance'
28 expect(subject.redis).to be == 'an other redis instance'
31 describe 'load_credentials' do
33 it 'should load credentials' do
35 expect(redis).to receive(:get).and_return(credentials_hash.to_json)
36 expect(subject.load_credentials).to be == credentials_hash
39 it 'should return nil' do
41 expect(redis).to receive(:get).and_return(nil)
42 expect(subject.load_credentials).to be_nil
46 describe 'redis_credentials_key' do
47 context 'without given key' do
48 it 'should return default key' do
49 expect(subject.redis_credentials_key).to be == "google_api_credentials"
52 context 'with given key' do
53 let(:redis_store) { Google::APIClient::RedisStore.new('a redis instance', 'another_google_api_credentials') }
54 it 'should use given key' do
55 expect(redis_store.redis_credentials_key).to be == "another_google_api_credentials"
61 describe 'write credentials' do
63 it 'should write credentials' do
65 expect(redis).to receive(:set).and_return('ok')
66 expect(subject.write_credentials(credentials_hash)).to be_truthy