From 0b717c20458d12191f479fc693dd1ca1eb11c050 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Mon, 5 Feb 2018 19:33:35 -0600 Subject: Provide an alternative PDF previewer based on Poppler mutool is licensed under the Affero GPL, which has strict distribution requirements. Poppler is licensed under the more liberal GPL, making it a good alternative for those who can't use mutool. --- .../test/previewer/mupdf_previewer_test.rb | 23 ++++++++++++++++++++++ activestorage/test/previewer/pdf_previewer_test.rb | 23 ---------------------- .../test/previewer/poppler_pdf_previewer_test.rb | 23 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 activestorage/test/previewer/mupdf_previewer_test.rb delete mode 100644 activestorage/test/previewer/pdf_previewer_test.rb create mode 100644 activestorage/test/previewer/poppler_pdf_previewer_test.rb (limited to 'activestorage/test') diff --git a/activestorage/test/previewer/mupdf_previewer_test.rb b/activestorage/test/previewer/mupdf_previewer_test.rb new file mode 100644 index 0000000000..6c2db6fcbf --- /dev/null +++ b/activestorage/test/previewer/mupdf_previewer_test.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "test_helper" +require "database/setup" + +require "active_storage/previewer/mupdf_previewer" + +class ActiveStorage::Previewer::MuPDFPreviewerTest < ActiveSupport::TestCase + setup do + @blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") + end + + test "previewing a PDF document" do + ActiveStorage::Previewer::MuPDFPreviewer.new(@blob).preview do |attachable| + 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 +end diff --git a/activestorage/test/previewer/pdf_previewer_test.rb b/activestorage/test/previewer/pdf_previewer_test.rb deleted file mode 100644 index fe32f39be4..0000000000 --- a/activestorage/test/previewer/pdf_previewer_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" -require "database/setup" - -require "active_storage/previewer/pdf_previewer" - -class ActiveStorage::Previewer::PDFPreviewerTest < ActiveSupport::TestCase - setup do - @blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") - end - - test "previewing a PDF document" do - ActiveStorage::Previewer::PDFPreviewer.new(@blob).preview do |attachable| - 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 -end diff --git a/activestorage/test/previewer/poppler_pdf_previewer_test.rb b/activestorage/test/previewer/poppler_pdf_previewer_test.rb new file mode 100644 index 0000000000..2b41c8b642 --- /dev/null +++ b/activestorage/test/previewer/poppler_pdf_previewer_test.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "test_helper" +require "database/setup" + +require "active_storage/previewer/poppler_pdf_previewer" + +class ActiveStorage::Previewer::PopplerPDFPreviewerTest < ActiveSupport::TestCase + setup do + @blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") + end + + test "previewing a PDF document" do + ActiveStorage::Previewer::PopplerPDFPreviewer.new(@blob).preview do |attachable| + 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 +end -- cgit v1.2.3