Sha256: d8f3e3c7b78b6f57d4d3675511ae780302415b05d300dd2cc3a0bb789d3b06bc

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

require "test_helper"
require "database/setup"

require "mini_magick"

class ActiveStorage::Previewer::OfficePreviewerTest < ActiveSupport::TestCase
  test "previewing a Word document" do
    blob = create_file_blob \
      filename: "hello.docx",
      content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

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

      image = MiniMagick::Image.read(attachable[:io])
      assert_equal 1088, image.width
      assert_equal 1408, image.height
      assert_equal "image/png", image.mime_type
    end
  end

  test "previewing a PowerPoint presentation" do
    blob = create_file_blob \
      filename: "hello.pptx",
      content_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation"

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

      image = MiniMagick::Image.read(attachable[:io])
      assert_equal 1820, image.width
      assert_equal 1365, image.height
      assert_equal "image/png", image.mime_type
    end
  end

  test "previewing an Excel spreadsheet" do
    blob = create_file_blob \
      filename: "hello.xlsx",
      content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

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

      image = MiniMagick::Image.read(attachable[:io])
      assert_equal 1088, image.width
      assert_equal 1408, image.height
      assert_equal "image/png", image.mime_type
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activestorage-office-previewer-0.1.1 test/office_previewer_test.rb
activestorage-office-previewer-0.1.0 test/office_previewer_test.rb