master
 1require "rails_helper"
 2
 3if ENV['AWS_SECRET_ACCESS_KEY'].present?
 4  describe BlobStorage do
 5    let(:bucket) { ENV['FOG_DIRECTORY'] }
 6    subject { BlobStorage.new }
 7
 8    let(:file) { File.join(Rails.root, 'spec/fixtures/images/gorilla.jpg') }
 9
10    context "when uploading" do
11      let(:key) { "test#{SecureRandom.uuid}" }
12
13      it "uploads to s3" do
14        subject.upload(key, file)
15
16        object = AWS::S3.new.buckets[bucket].objects[key]
17        expect(object.exists?).to be_truthy
18      end
19    end
20
21    describe "#download" do
22      let(:key) { "test/upload/#{SecureRandom.uuid}" }
23
24      it 'downloads a file from blob storage' do
25        subject.upload(key, file)
26
27        sha = subject.download(key) do |temp_file|
28          Digest::SHA256.file(temp_file.path).hexdigest
29        end
30        expect(sha).to eql(Digest::SHA256.file(file).hexdigest)
31      end
32    end
33  end
34end