Sha256: 39b4a4e7a1fce70862cf2b81b3f4ba8c9ad1ba66dbf1955f92676ae87967ad5f

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe Hydra::Derivatives::Image do
  let(:object) { ActiveFedora::Base.new }
  let(:output_file) { double }

  subject { Hydra::Derivatives::Image.new(object, 'content', directives)}

  before { allow(subject).to receive(:output_file).with(file_name).and_return(output_file) }

  describe "when arguments are passed as a string" do
    let(:directives) { { thumb: "100x100>" } }
    let(:file_name) { 'content_thumb' }

    it "should use the string as the size and the name is autogenerated" do
      expect(subject).to receive(:create_resized_image).with(output_file, "100x100>", 'png')
      subject.process
    end
  end

  describe "when arguments are passed as a hash" do
    let(:directives) { { thumb: { size: "200x300>", datastream: file_name } } }
    let(:file_name) { 'thumbnail' }

    it "should use the specified size and name" do
      expect(subject).to receive(:create_resized_image).with(output_file, "200x300>", 'png')
      subject.process
    end
  end

  describe 'timeout' do
    let(:directives) { { thumb: "100x100>" } }
    let(:file_name) { 'content_thumb' }

    before do
      allow(subject).to receive(:create_resized_image).with(output_file, "100x100>", 'png')
    end

    context 'when set' do
      before do
        subject.timeout = 0.1
        allow_any_instance_of(Hydra::Derivatives::Image).to receive(:process_without_timeout) { sleep 0.2 }
      end
      it 'raises a timeout exception' do
        expect { subject.process }.to raise_error Hydra::Derivatives::TimeoutError
      end
    end

    context 'when not set' do
      before { subject.timeout = nil }
      it 'processes without a timeout' do
        expect(subject).to receive(:process_with_timeout).never
        expect(subject).to receive(:process_without_timeout).once
        subject.process
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hydra-derivatives-1.2.1 spec/units/image_spec.rb
hydra-derivatives-1.2.0 spec/units/image_spec.rb
hydra-derivatives-1.1.0 spec/units/image_spec.rb