adds specs for redis_store
authorVolker Zöpfel <volker@zoepfel.de>
Tue, 3 Dec 2013 07:42:01 +0000 (08:42 +0100)
committerVolker Zöpfel <volker@zoepfel.de>
Tue, 3 Dec 2013 07:42:01 +0000 (08:42 +0100)
spec/google/api_client/auth/storages/redis_store_spec.rb

index ba5b889238845f9da8e2f39a0693a2774e3d9a77..9f653bf6476ba76d9d525479eea7c5a14391c167 100644 (file)
@@ -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