Sha256: de371bb067eba2a8d08b0ece25eacc7ec84cb82808048a1a9054d49d11b97599

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe Hydra::Derivatives::Processors::Image do
  let(:output_file) { double }
  let(:file_name) { double }

  subject { described_class.new(file_name, directives) }

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

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

    it "uses the specified size and name and quality" do
      expect(subject).to receive(:create_resized_image).with(file_name, "200x300>", 'png', 75)
      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("100x100>", 'png')
    end

    context 'when set' do
      before do
        subject.timeout = 0.1
        allow_any_instance_of(described_class).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

7 entries across 7 versions & 1 rubygems

Version Path
hydra-derivatives-3.1.3 spec/processors/image_spec.rb
hydra-derivatives-3.1.2 spec/processors/image_spec.rb
hydra-derivatives-3.1.1 spec/processors/image_spec.rb
hydra-derivatives-3.1.0 spec/processors/image_spec.rb
hydra-derivatives-3.0.2 spec/processors/image_spec.rb
hydra-derivatives-3.0.1 spec/processors/image_spec.rb
hydra-derivatives-3.0.0 spec/processors/image_spec.rb