add specs

This commit is contained in:
Lisa Durand 2024-05-07 16:27:08 +02:00 committed by Eric Leroy-Terquem
parent b4a7b4bfbd
commit 93c3761107
No known key found for this signature in database
GPG key ID: ECE60B4C1FA2ABB3
7 changed files with 129 additions and 30 deletions

View file

@ -1,14 +1,32 @@
RSpec.describe AutoRotateService do
let(:image) { file_fixture("image-rotated.jpg") }
let(:image_no_exif) { file_fixture("image-no-exif.jpg") }
let(:image_no_rotation) { file_fixture("image-no-rotation.jpg") }
let(:auto_rotate_service) { AutoRotateService.new }
describe '#process' do
it 'returns a tempfile if auto_rotate succeeds' do
Tempfile.create do |output|
auto_rotate_service.process(image, output)
result = auto_rotate_service.process(image, output)
expect(MiniMagick::Image.new(image.to_path)["%[orientation]"]).to eq('LeftBottom')
expect(MiniMagick::Image.new(output.to_path)["%[orientation]"]).to eq('TopLeft')
expect(output.size).to be_between(image.size / 1.2, image.size)
expect(result.size).to be_between(image.size / 1.2, image.size)
end
end
it 'returns nil if image does not need to be return' do
Tempfile.create do |output|
result = auto_rotate_service.process(image_no_rotation, output)
expect(MiniMagick::Image.new(image_no_rotation.to_path)["%[orientation]"]).to eq('TopLeft')
expect(result).to eq nil
end
end
it 'returns nil if no exif info on image' do
Tempfile.create do |output|
result = auto_rotate_service.process(image_no_exif, output)
expect(MiniMagick::Image.new(image_no_exif.to_path)["%[orientation]"]).to eq('Undefined')
expect(result).to eq nil
end
end
end