Commit eef9f2a

mo khan <mo@mokhan.ca>
2014-07-25 21:50:35
dump all secrets.
1 parent 21c34f9
Changed files (2)
lib/tfa/show_command.rb
@@ -5,9 +5,17 @@ module TFA
     end
 
     def run(arguments)
-      name = arguments.last
-      @storage.transaction(true) do
-        @storage[name]
+      if arguments.any?
+        name = arguments.last
+        @storage.transaction(true) do
+          @storage[name]
+        end
+      else
+        @storage.transaction(true) do
+          @storage.roots.map do |key|
+            @storage[key]
+          end
+        end
       end
     end
   end
spec/lib/show_command_spec.rb
@@ -3,14 +3,30 @@ module TFA
     subject { ShowCommand.new(storage) }
     let(:storage) { PStore.new(Tempfile.new('blah').path) }
 
-    it "retrieves the secret associated with the key given" do
-      secret = SecureRandom.uuid
-      storage.transaction do
-        storage['production'] = secret
+    describe "#run" do
+      context "when looking up the secret for a specific key" do
+        it "retrieves the secret associated with the key given" do
+          secret = SecureRandom.uuid
+          storage.transaction do
+            storage['production'] = secret
+          end
+
+          result = subject.run(['production'])
+          expect(result).to eql(secret)
+        end
       end
 
-      result = subject.run(['production'])
-      expect(result).to eql(secret)
+      context "when a specific name is not given" do
+        it "returns all the secrets" do
+          storage.transaction do
+            storage['development'] = "1"
+            storage['staging'] = "2"
+            storage['production'] = "3"
+          end
+
+          expect(subject.run([])).to eql(["1", "2", "3"])
+        end
+      end
     end
   end
 end