spec/models/riiif/image_spec.rb in riiif-1.1.1 vs spec/models/riiif/image_spec.rb in riiif-1.1.2

- old
+ new

@@ -1,8 +1,8 @@ require 'spec_helper' -describe Riiif::Image do +RSpec.describe Riiif::Image do before { Rails.cache.clear } let(:filename) { File.expand_path('spec/samples/world.jp2') } subject { described_class.new('world') } describe 'happy path' do before do @@ -14,22 +14,22 @@ end it 'is able to override the file used for the Image' do img = described_class.new('some_id', Riiif::File.new(filename)) expect(img.id).to eq 'some_id' - expect(img.info).to eq height: 400, width: 800 + expect(img.info).to eq Riiif::ImageInformation.new(800, 400) end describe 'without a format' do it 'raises an error' do expect { subject.render('size' => 'full') }.to raise_error ArgumentError end end describe 'info' do it 'returns the data' do - expect(subject.info).to eq height: 400, width: 800 + expect(subject.info).to eq Riiif::ImageInformation.new(800, 400) end end context 'using HTTPFileResolver' do before do @@ -43,11 +43,11 @@ end describe 'get info' do subject { described_class.new('Cave_26,_Ajanta') } it 'is easy' do - expect(subject.info).to eq height: 390, width: 600 + expect(subject.info).to eq Riiif::ImageInformation.new(600, 390) end end context 'when the rendered image is in the cache' do subject { described_class.new('Cave_26,_Ajanta') } @@ -61,94 +61,100 @@ end describe 'mogrify' do describe 'region' do it 'returns the original when specifing full size' do - expect(subject.image).to receive(:execute).with("convert #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert #{filename} png:-") subject.render(region: 'full', format: 'png') end it 'handles absolute geometry' do - expect(subject.image).to receive(:execute).with("convert -crop 60x75+80+15 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -crop 60x75+80+15 #{filename} png:-") subject.render(region: '80,15,60,75', format: 'png') end + it 'handles percent geometry' do - expect(subject.image).to receive(:execute).with("identify -format %hx%w #{filename}").and_return('131x175') - expect(subject.image).to receive(:execute).with("convert -crop 80%x70+18+13 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute) + .with("identify -format %hx%w #{filename}").and_return('131x175') + expect(Riiif::CommandRunner).to receive(:execute).with("convert -crop 80%x70+18+13 #{filename} png:-") subject.render(region: 'pct:10,10,80,70', format: 'png') end + it 'handles square geometry' do - expect(subject.image).to receive(:execute).with("identify -format %hx%w #{filename}").and_return('131x175') - expect(subject.image).to receive(:execute).with("convert -crop 131x131+22+0 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute) + .with("identify -format %hx%w #{filename}").and_return('131x175') + expect(Riiif::CommandRunner).to receive(:execute).with("convert -crop 131x131+22+0 #{filename} png:-") subject.render(region: 'square', format: 'png') end it 'raises an error for invalid geometry' do expect { subject.render(region: '150x75', format: 'png') }.to raise_error Riiif::InvalidAttributeError end end describe 'resize' do it 'returns the original when specifing full size' do - expect(subject.image).to receive(:execute).with("convert #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert #{filename} png:-") subject.render(size: 'full', format: 'png') end it 'handles integer percent sizes' do - expect(subject.image).to receive(:execute).with("convert -resize 50% #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -resize 50% #{filename} png:-") subject.render(size: 'pct:50', format: 'png') end it 'handles float percent sizes' do - expect(subject.image).to receive(:execute).with("convert -resize 12.5% #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -resize 12.5% #{filename} png:-") subject.render(size: 'pct:12.5', format: 'png') end it 'handles w,' do - expect(subject.image).to receive(:execute).with("convert -resize 50 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -resize 50 #{filename} png:-") subject.render(size: '50,', format: 'png') end it 'handles ,h' do - expect(subject.image).to receive(:execute).with("convert -resize x50 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -resize x50 #{filename} png:-") subject.render(size: ',50', format: 'png') end it 'handles w,h' do - expect(subject.image).to receive(:execute).with("convert -resize 150x75! #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -resize 150x75! #{filename} png:-") subject.render(size: '150,75', format: 'png') end it 'handles bestfit (!w,h)' do - expect(subject.image).to receive(:execute).with("convert -resize 150x75 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -resize 150x75 #{filename} png:-") subject.render(size: '!150,75', format: 'png') end it 'raises an error for invalid size' do expect { subject.render(size: '150x75', format: 'png') }.to raise_error Riiif::InvalidAttributeError end end describe 'rotate' do it 'returns the original when specifing full size' do - expect(subject.image).to receive(:execute).with("convert #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert #{filename} png:-") subject.render(rotation: '0', format: 'png') end it 'handles floats' do - expect(subject.image).to receive(:execute).with("convert -virtual-pixel white +distort srt 22.5 #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute) + .with("convert -virtual-pixel white +distort srt 22.5 #{filename} png:-") subject.render(rotation: '22.5', format: 'png') end it 'raises an error for invalid angle' do expect { subject.render(rotation: '150x', format: 'png') }.to raise_error Riiif::InvalidAttributeError end end describe 'quality' do it 'returns the original when specifing default' do - expect(subject.image).to receive(:execute).with("convert #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert #{filename} png:-") subject.render(quality: 'default', format: 'png') end it 'returns the original when specifing color' do - expect(subject.image).to receive(:execute).with("convert #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert #{filename} png:-") subject.render(quality: 'color', format: 'png') end it 'converts to grayscale' do - expect(subject.image).to receive(:execute).with("convert -colorspace Gray #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute).with("convert -colorspace Gray #{filename} png:-") subject.render(quality: 'grey', format: 'png') end it 'converts to bitonal' do - expect(subject.image).to receive(:execute).with("convert -colorspace Gray -type Bilevel #{filename} png:-") + expect(Riiif::CommandRunner).to receive(:execute) + .with("convert -colorspace Gray -type Bilevel #{filename} png:-") subject.render(quality: 'bitonal', format: 'png') end it 'raises an error for invalid angle' do expect { subject.render(rotation: '150x', format: 'png') }.to raise_error Riiif::InvalidAttributeError end