Skip to content

Commit 3d1568d

Browse files
committed
adds specs for redis_store
1 parent 71eeabe commit 3d1568d

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

spec/google/api_client/auth/storages/redis_store_spec.rb

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,51 @@
22
require_relative '../../../../../lib/google/api_client/auth/storages/redis_store'
33

44
describe Google::APIClient::RedisStore do
5+
let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..', '..', '..')) }
56
let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
7+
let(:redis) {double}
68

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+
} }
819

9-
it 'should load credentials'
20+
subject { Google::APIClient::RedisStore.new('a redis instance') }
1021

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
1251

1352
end

0 commit comments

Comments
 (0)