demarches-normaliennes/spec/services/auto_rotate_service_spec.rb

36 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe AutoRotateService do
let(:image) { file_fixture("image-rotated.jpg") }
2024-05-07 16:27:08 +02:00
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|
2024-05-07 16:27:08 +02:00
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')
2024-05-07 16:27:08 +02:00
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
end