mupdf_previewer_test.rb 1.1 KB
Newer Older
G
George Claghorn 已提交
1 2
# frozen_string_literal: true

3 4 5
require "test_helper"
require "database/setup"

6
require "active_storage/previewer/mupdf_previewer"
G
George Claghorn 已提交
7

8
class ActiveStorage::Previewer::MuPDFPreviewerTest < ActiveSupport::TestCase
G
George Claghorn 已提交
9
  test "previewing a PDF document" do
10 11 12
    blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf")

    ActiveStorage::Previewer::MuPDFPreviewer.new(blob).preview do |attachable|
G
George Claghorn 已提交
13 14 15 16 17 18 19 20
      assert_equal "image/png", attachable[:content_type]
      assert_equal "report.png", attachable[:filename]

      image = MiniMagick::Image.read(attachable[:io])
      assert_equal 612, image.width
      assert_equal 792, image.height
    end
  end
21 22 23 24 25 26 27 28 29 30 31 32 33

  test "previewing a cropped PDF document" do
    blob = create_file_blob(filename: "cropped.pdf", content_type: "application/pdf")

    ActiveStorage::Previewer::MuPDFPreviewer.new(blob).preview do |attachable|
      assert_equal "image/png", attachable[:content_type]
      assert_equal "cropped.png", attachable[:filename]

      image = MiniMagick::Image.read(attachable[:io])
      assert_equal 430, image.width
      assert_equal 145, image.height
    end
  end
G
George Claghorn 已提交
34
end