2017-10-22 13:16:59 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
|
|
|
require "database/setup"
|
|
|
|
|
|
|
|
require "active_storage/analyzer/image_analyzer"
|
|
|
|
|
|
|
|
class ActiveStorage::Analyzer::ImageAnalyzerTest < ActiveSupport::TestCase
|
2017-12-31 10:36:58 -05:00
|
|
|
test "analyzing a JPEG image" do
|
2017-10-22 13:16:59 -04:00
|
|
|
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
|
2018-01-31 15:43:29 -05:00
|
|
|
metadata = extract_metadata_from(blob)
|
|
|
|
|
|
|
|
assert_equal 4104, metadata[:width]
|
|
|
|
assert_equal 2736, metadata[:height]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "analyzing a rotated JPEG image" do
|
|
|
|
blob = create_file_blob(filename: "racecar_rotated.jpg", content_type: "image/jpeg")
|
|
|
|
metadata = extract_metadata_from(blob)
|
2017-10-22 13:16:59 -04:00
|
|
|
|
2018-01-31 16:50:30 -05:00
|
|
|
assert_equal 2736, metadata[:width]
|
|
|
|
assert_equal 4104, metadata[:height]
|
2017-10-22 13:16:59 -04:00
|
|
|
end
|
2017-12-31 10:36:58 -05:00
|
|
|
|
|
|
|
test "analyzing an SVG image without an XML declaration" do
|
|
|
|
blob = create_file_blob(filename: "icon.svg", content_type: "image/svg+xml")
|
2018-01-31 15:43:29 -05:00
|
|
|
metadata = extract_metadata_from(blob)
|
2017-12-31 10:36:58 -05:00
|
|
|
|
|
|
|
assert_equal 792, metadata[:width]
|
|
|
|
assert_equal 584, metadata[:height]
|
|
|
|
end
|
2019-04-23 16:11:10 -04:00
|
|
|
|
|
|
|
test "analyzing an unsupported image type" do
|
|
|
|
blob = create_blob(data: "bad", filename: "bad_file.bad", content_type: "image/bad_type")
|
|
|
|
metadata = extract_metadata_from(blob)
|
|
|
|
|
|
|
|
assert_nil metadata[:width]
|
|
|
|
assert_nil metadata[:heigh]
|
|
|
|
end
|
2017-10-22 13:16:59 -04:00
|
|
|
end
|