Commit d569fbe0

mo khan <mo@mokhan.ca>
2015-01-11 07:31:50
run blob storage specs if key specified.
1 parent 0286932
Changed files (1)
spec
services
infrastructure
spec/services/infrastructure/blob_storage_spec.rb
@@ -1,31 +1,34 @@
 require "rails_helper"
 
-describe BlobStorage do
-  let(:bucket) { ENV['FOG_DIRECTORY'] }
-  subject { BlobStorage.new }
+if ENV['AWS_SECRET_ACCESS_KEY'].present?
+  describe BlobStorage do
+    let(:bucket) { ENV['FOG_DIRECTORY'] }
+    subject { BlobStorage.new }
 
-  let(:file) { File.join(Rails.root, 'spec/fixtures/images/gorilla.jpg') }
+    let(:file) { File.join(Rails.root, 'spec/fixtures/images/gorilla.jpg') }
 
-  context "when uploading" do
-    it "uploads to s3" do
-      key = "test#{SecureRandom.uuid}"
-      subject.upload(key, file)
+    context "when uploading" do
+      let(:key) { "test#{SecureRandom.uuid}" }
 
-      object = AWS::S3.new.buckets[bucket].objects[key]
-      expect(object.exists?).to be_truthy
+      it "uploads to s3" do
+        subject.upload(key, file)
+
+        object = AWS::S3.new.buckets[bucket].objects[key]
+        expect(object.exists?).to be_truthy
+      end
     end
-  end
 
-  describe "#download" do
-    let(:key) { "test/upload/#{SecureRandom.uuid}" }
+    describe "#download" do
+      let(:key) { "test/upload/#{SecureRandom.uuid}" }
 
-    it 'downloads a file from blob storage' do
-      subject.upload(key, file)
+      it 'downloads a file from blob storage' do
+        subject.upload(key, file)
 
-      sha = subject.download(key) do |temp_file|
-        Digest::SHA256.file(temp_file.path).hexdigest
+        sha = subject.download(key) do |temp_file|
+          Digest::SHA256.file(temp_file.path).hexdigest
+        end
+        expect(sha).to eql(Digest::SHA256.file(file).hexdigest)
       end
-      expect(sha).to eql(Digest::SHA256.file(file).hexdigest)
     end
   end
 end