adds specs for storage
authorVolker Zöpfel <volker@zoepfel.de>
Thu, 28 Nov 2013 07:14:41 +0000 (08:14 +0100)
committerVolker Zöpfel <volker@zoepfel.de>
Thu, 28 Nov 2013 07:14:41 +0000 (08:14 +0100)
changes expectation in write_credentials

lib/google/api_client/auth/storage.rb
spec/google/api_client/auth/storage_spec.rb

index db308e5e6af39e1a7a97c3e65715d737a7992cc3..5197cf2d78682f75391c5381ecdd5a3b40adaf83 100644 (file)
@@ -48,7 +48,7 @@ module Google
       #    already associated with this instance will be written.
       def write_credentials(authorization=nil)
         @authorization = authorization if authorization
-        if @authorization.refresh_token
+        if @authorization.respond_to?(:refresh_token) && @authorization.refresh_token
           store.write_credentials(credentials_hash)
         end
       end
index b61057df3e7507c62d709890376a9c800a45d07b..1c319f4b7137bb4aba0af6ef9efe6d86f45f06f1 100644 (file)
@@ -40,8 +40,8 @@ describe Google::APIClient::Storage do
         subject.should_receive(:refresh_authorization)
         subject.authorize
       end
-
     end
+
     describe 'without credentials' do
 
       it 'should return false' do
@@ -51,19 +51,34 @@ describe Google::APIClient::Storage do
     end
   end
 
-
   describe 'write_credentials' do
+    it 'should call store to write credentials' do
+      authorization_stub = double
+      authorization_stub.should_receive(:refresh_token).and_return(true)
+      subject.should_receive(:credentials_hash)
+      subject.store.should_receive(:write_credentials)
+      subject.write_credentials(authorization_stub)
+      subject.authorization.should == authorization_stub
+    end
 
-    it 'should store credentials to var'
-
-    it 'should call store to write credentials'
-
-    it 'should not call store to write credentials'
+    it 'should not call store to write credentials' do
+      subject.should_not_receive(:credentials_hash)
+      subject.store.should_not_receive(:write_credentials)
+      expect {
+        subject.write_credentials()
+      }.not_to raise_error
+    end
+    it 'should not call store to write credentials' do
+      subject.should_not_receive(:credentials_hash)
+      subject.store.should_not_receive(:write_credentials)
+      expect {
+        subject.write_credentials('something')
+      }.not_to raise_error
+    end
 
   end
 
   describe 'refresh_authorization' do
-
     it 'should call refresh and write credentials' do
       subject.should_receive(:write_credentials)
       authorization_stub = double
@@ -74,8 +89,31 @@ describe Google::APIClient::Storage do
   end
 
   describe 'load_credentials' do
-    it 'should call store to load credentials'
-
+    it 'should call store to load credentials' do
+      subject.store.should_receive(:load_credentials)
+      subject.send(:load_credentials)
+    end
   end
 
+  describe 'credentials_hash' do
+    it 'should return an hash' do
+      authorization_stub = double
+      authorization_stub.should_receive(:access_token)
+      authorization_stub.should_receive(:client_id)
+      authorization_stub.should_receive(:client_secret)
+      authorization_stub.should_receive(:expires_in)
+      authorization_stub.should_receive(:refresh_token)
+      authorization_stub.should_receive(:issued_at).and_return('100')
+      subject.stub(:authorization).and_return(authorization_stub)
+      credentials = subject.send(:credentials_hash)
+      credentials.should include(:access_token)
+      credentials.should include(:authorization_uri)
+      credentials.should include(:client_id)
+      credentials.should include(:client_secret)
+      credentials.should include(:expires_in)
+      credentials.should include(:refresh_token)
+      credentials.should include(:token_credential_uri)
+      credentials.should include(:issued_at)
+    end
+  end
 end