Sha256: 990ef73069d1dafe14bb4648b916d85ddd4cb1318ad6454690c6d0dec7146712

Contents?: true

Size: 1.87 KB

Versions: 5

Compression:

Stored size: 1.87 KB

Contents

require 'rails_helper'
require 'shrine/plugins/kithe_checksum_signatures'

# This kithe plugin is optional, let's make sure it works how we expect
describe Shrine::Plugins::KitheChecksumSignatures, queue_adpater: :inline do
  temporary_class("ChecksumUploader") do
    Class.new(Kithe::AssetUploader) do
      plugin :kithe_checksum_signatures
    end
  end

  temporary_class("ChecksumAsset") do
    Class.new(Kithe::Asset) do
      set_shrine_uploader(ChecksumUploader)
    end
  end

  around do |example|
    original = Kithe::Asset.promotion_directives
    Kithe::Asset.promotion_directives = { promote: :inline }

    example.run

    Kithe::Asset.promotion_directives = original
  end

  it "provides checksum metadata after promotion" do
    asset = ChecksumAsset.create!(title: "test", file: StringIO.new("test"))
    asset.reload

    expect(asset).to be_stored
    expect(asset.file.metadata.slice("md5", "sha1", "sha512")).to all(be_present)
  end

  describe "without promotion" do
    around do |example|
      original = Kithe::Asset.promotion_directives
      Kithe::Asset.promotion_directives = { promote: false }

      example.run

      Kithe::Asset.promotion_directives = original
    end

    it "does not extract checksum metadata on cache" do
      asset = ChecksumAsset.create!(title: "test", file: StringIO.new("test"))
      asset.reload

      expect(asset).not_to be_stored
      expect(asset.file.metadata.slice("md5", "sha1", "sha512")).not_to include(be_present)
    end
  end

  describe "derivatives" do
    it "do not get checksum metadata" do
      asset = ChecksumAsset.create!(title: "test", file: StringIO.new("test"))
      asset.update_derivative("test", StringIO.new("test deriv"))

      expect(asset.file_derivatives[:test]).to be_present
      expect(asset.file_derivatives[:test].metadata.slice("md5", "sha1", "sha512")).not_to include(be_present)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kithe-2.0.2 spec/shrine/kithe_checksum_signatures_spec.rb
kithe-2.0.1 spec/shrine/kithe_checksum_signatures_spec.rb
kithe-2.0.0 spec/shrine/kithe_checksum_signatures_spec.rb
kithe-2.0.0.pre.rc1 spec/shrine/kithe_checksum_signatures_spec.rb
kithe-2.0.0.pre.beta1 spec/shrine/kithe_checksum_signatures_spec.rb