From 3d1568d67ff618c548ee057daf3878e4608e4073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20Z=C3=B6pfel?= Date: Tue, 3 Dec 2013 08:42:01 +0100 Subject: [PATCH] adds specs for redis_store --- .../auth/storages/redis_store_spec.rb | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/spec/google/api_client/auth/storages/redis_store_spec.rb b/spec/google/api_client/auth/storages/redis_store_spec.rb index ba5b88923..9f653bf64 100644 --- a/spec/google/api_client/auth/storages/redis_store_spec.rb +++ b/spec/google/api_client/auth/storages/redis_store_spec.rb @@ -2,12 +2,51 @@ require 'spec_helper' require_relative '../../../../../lib/google/api_client/auth/storages/redis_store' describe Google::APIClient::RedisStore do + let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..', '..', '..')) } let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) } + let(:redis) {double} - it 'should initialize' + let(:credentials_hash) { { + "access_token" => "my_access_token", + "authorization_uri" => "https://accounts.google.com/o/oauth2/auth", + "client_id" => "123456_test_client_id@.apps.googleusercontent.com", + "client_secret" => "123456_client_secret", + "expires_in" => 3600, + "refresh_token" => "my_refresh_token", + "token_credential_uri" => "https://accounts.google.com/o/oauth2/token", + "issued_at" => 1384440275 + } } - it 'should load credentials' + subject { Google::APIClient::RedisStore.new('a redis instance') } - it 'should write credentials' + it 'should have a redis instance' do + subject.redis.should == 'a redis instance' + subject.redis = 'an other redis instance' + subject.redis.should == 'an other redis instance' + end + + describe 'load_credentials' do + + it 'should load credentials' do + subject.redis= redis + redis.should_receive(:get).and_return(credentials_hash.to_json) + subject.load_credentials.should == credentials_hash + end + + it 'should return nil' do + subject.redis= redis + redis.should_receive(:get).and_return(nil) + subject.load_credentials.should == nil + end + end + + describe 'write credentials' do + + it 'should write credentials' do + subject.redis= redis + redis.should_receive(:set).and_return('ok') + subject.write_credentials(credentials_hash).should be_true + end + end end