Sha256: 3d05e95365480e53a3f460e6f6a31dacf79874c14c53e0c05c01804b25e20b51

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require File.expand_path("../../spec_helper", __FILE__)

RSpec.describe Attachie::S3Driver do
  let(:driver) do
    Attachie::S3Driver.new(Aws::S3::Client.new(
      access_key_id: "access_key_id",
      secret_access_key: "secret_access_key",
      endpoint: "http://localhost:4569",
      region: "us-east-1"
    ))
  end

  it "should list objects" do
    begin
      driver.store("object1", "blob", "bucket")
      driver.store("object2", "blob", "bucket")
      driver.store("other", "blob", "bucket")

      expect(driver.list("bucket", prefix: "object").to_a).to eq(["object1", "object2"])
    ensure
      driver.delete("object1", "bucket")
      driver.delete("object2", "bucket")
      driver.delete("other", "bucket")
    end
  end

  it "should store a blob" do
    begin
      driver.store("name", "blob", "bucket")

      expect(driver.exists?("name", "bucket")).to be(true)
      expect(driver.value("name", "bucket")).to eq("blob")
    ensure
      driver.delete("name", "bucket")
    end
  end

  it "should store a blob via multipart upload" do
    begin
      driver.store_multipart("name", "bucket") do |upload|
        upload.upload_part("chunk1")
        upload.upload_part("chunk2")
      end

      expect(driver.exists?("name", "bucket")).to be(true)
      expect(driver.value("name", "bucket")).to eq("chunk1chunk2")
    ensure
      driver.delete("name", "bucket")
    end
  end

  it "should delete a blob" do
    begin
      driver.store("name", "blob", "bucket")
      expect(driver.exists?("name", "bucket")).to be(true)

      driver.delete("name", "bucket")
      expect(driver.exists?("name", "bucket")).to be(false)
    ensure
      driver.delete("name", "bucket")
    end
  end

  it "should generate a temp_url" do
    expect(driver.temp_url("name", "bucket")).to be_url
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attachie-0.0.1 spec/attachie/s3_driver_spec.rb