diff options
author | George Claghorn <george.claghorn@gmail.com> | 2017-10-12 11:47:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 11:47:21 -0400 |
commit | 445c682a8465b1a42f1335ae2cf7d20b9a112fcd (patch) | |
tree | e86aac9a6dfba21a78b7ce1901a95adc7b42a9ab /activestorage/test | |
parent | 8bcb4fab366611d3e9b34690682415281440c128 (diff) | |
download | rails-445c682a8465b1a42f1335ae2cf7d20b9a112fcd.tar.gz rails-445c682a8465b1a42f1335ae2cf7d20b9a112fcd.tar.bz2 rails-445c682a8465b1a42f1335ae2cf7d20b9a112fcd.zip |
Introduce ActiveStorage::Blob#representation
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/preview_test.rb | 2 | ||||
-rw-r--r-- | activestorage/test/models/representation_test.rb | 41 |
2 files changed, 43 insertions, 0 deletions
diff --git a/activestorage/test/models/preview_test.rb b/activestorage/test/models/preview_test.rb index 317a2d5c58..bcd8442f4b 100644 --- a/activestorage/test/models/preview_test.rb +++ b/activestorage/test/models/preview_test.rb @@ -7,6 +7,7 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase test "previewing a PDF" do blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") preview = blob.preview(resize: "640x280").processed + assert preview.image.attached? assert_equal "report.png", preview.image.filename.to_s assert_equal "image/png", preview.image.content_type @@ -19,6 +20,7 @@ class ActiveStorage::PreviewTest < ActiveSupport::TestCase test "previewing an MP4 video" do blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4") preview = blob.preview(resize: "640x280").processed + assert preview.image.attached? assert_equal "video.png", preview.image.filename.to_s assert_equal "image/png", preview.image.content_type diff --git a/activestorage/test/models/representation_test.rb b/activestorage/test/models/representation_test.rb new file mode 100644 index 0000000000..29fe61aee4 --- /dev/null +++ b/activestorage/test/models/representation_test.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require "test_helper" +require "database/setup" + +class ActiveStorage::RepresentationTest < ActiveSupport::TestCase + test "representing an image" do + blob = create_file_blob + representation = blob.representation(resize: "100x100").processed + + image = read_image(representation.image) + assert_equal 100, image.width + assert_equal 67, image.height + end + + test "representing a PDF" do + blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") + representation = blob.representation(resize: "640x280").processed + + image = read_image(representation.image) + assert_equal 612, image.width + assert_equal 792, image.height + end + + test "representing an MP4 video" do + blob = create_file_blob(filename: "video.mp4", content_type: "video/mp4") + representation = blob.representation(resize: "640x280").processed + + image = read_image(representation.image) + assert_equal 640, image.width + assert_equal 480, image.height + end + + test "representing an unrepresentable blob" do + blob = create_blob + + assert_raises ActiveStorage::Blob::UnrepresentableError do + blob.representation resize: "100x100" + end + end +end |