Sha256: 8938de823c4192e379d92e51f39005855b61c0b636b23f5371d156b29ed3da7a

Contents?: true

Size: 1.74 KB

Versions: 10

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

describe Hyrax::DerivativePath do
  let(:id)     { '123' }
  let(:object) { double(id: id) }

  before { allow(Hyrax.config).to receive(:derivatives_path).and_return('tmp') }

  context "for a single path" do
    let(:destination_name) { 'thumbnail' }

    describe '.derivative_path_for_reference' do
      subject { described_class.derivative_path_for_reference(object, destination_name) }
      it { is_expected.to eq('tmp/12/3-thumbnail.jpeg') }
    end

    describe '#derivative_path' do
      context "with an object" do
        subject { described_class.new(object, destination_name).derivative_path }
        it { is_expected.to eq('tmp/12/3-thumbnail.jpeg') }
      end

      context "with an id" do
        subject { described_class.new(id, destination_name).derivative_path }
        it { is_expected.to eq('tmp/12/3-thumbnail.jpeg') }
      end
    end
  end

  context "for multiple paths" do
    before do
      FileUtils.mkdir_p("tmp/12")
      File.open("tmp/12/3-thumbnail.jpeg", 'w') do |f|
        f.write "test"
      end
      File.open("tmp/12/4-thumbnail.jpeg", 'w') do |f|
        f.write "test"
      end
    end
    after do
      FileUtils.rm_rf("tmp/12")
    end

    describe ".derivatives_for_reference" do
      subject { described_class.derivatives_for_reference(object) }
      it { is_expected.to eq(["tmp/12/3-thumbnail.jpeg"]) }
    end

    describe "#all_paths" do
      context "with an object" do
        subject { described_class.new(object, nil).all_paths }
        it { is_expected.to eq(["tmp/12/3-thumbnail.jpeg"]) }
      end

      context "with an id" do
        subject { described_class.new(id, nil).all_paths }
        it { is_expected.to eq(["tmp/12/3-thumbnail.jpeg"]) }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.1.0 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.5 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.4 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.3 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.2 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.1 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.0.rc2 spec/services/hyrax/derivative_path_spec.rb
hyrax-1.0.0.rc1 spec/services/hyrax/derivative_path_spec.rb
test_hyrax-0.0.1.alpha spec/services/hyrax/derivative_path_spec.rb