2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-04-22 15:12:49 +02:00
|
|
|
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") }
|
2024-04-22 15:12:49 +02:00
|
|
|
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)
|
2024-04-22 15:12:49 +02:00
|
|
|
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
|
2024-04-22 15:12:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|