From b502b04fc0bc137e1970137123c4feda60c0eb8b Mon Sep 17 00:00:00 2001 From: Nastia Gorokhova-Alekseeva Date: Thu, 30 Dec 2021 19:03:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=85=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D0=B2=20thumbnail=5Ftest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/thumbnail_test.rb | 70 ++++-------------------------------------- 1 file changed, 6 insertions(+), 64 deletions(-) diff --git a/test/thumbnail_test.rb b/test/thumbnail_test.rb index bdd0d83..0eb5faf 100644 --- a/test/thumbnail_test.rb +++ b/test/thumbnail_test.rb @@ -1,35 +1,8 @@ +# frozen_string_literal: true + require 'test_helper' class ThumbnailTest < Test::Unit::TestCase - - context "A Paperclip Tempfile" do - setup do - @tempfile = Paperclip::Tempfile.new("file.jpg") - end - - should "have its path contain a real extension" do - assert_equal ".jpg", File.extname(@tempfile.path) - end - - should "be a real Tempfile" do - assert @tempfile.is_a?(::Tempfile) - end - end - - context "Another Paperclip Tempfile" do - setup do - @tempfile = Paperclip::Tempfile.new("file") - end - - should "not have an extension if not given one" do - assert_equal "", File.extname(@tempfile.path) - end - - should "still be a real Tempfile" do - assert @tempfile.is_a?(::Tempfile) - end - end - context "An image" do setup do @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb') @@ -91,8 +64,9 @@ class ThumbnailTest < Test::Unit::TestCase end should "send the right command to convert when sent #make" do + Paperclip::Thumbnail.any_instance.stubs(:gamma_correction_if_needed).returns("PNG\nPaletteAlpha") Paperclip.expects(:"`").with do |arg| - arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"} + arg.match? %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-auto-orient\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+} end @thumb.make end @@ -115,8 +89,9 @@ class ThumbnailTest < Test::Unit::TestCase end should "send the right command to convert when sent #make" do + Paperclip::Thumbnail.any_instance.stubs(:gamma_correction_if_needed).returns("PNG\nPaletteAlpha") Paperclip.expects(:"`").with do |arg| - arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"} + arg.match? %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-auto-orient\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+} end @thumb.make end @@ -141,37 +116,4 @@ class ThumbnailTest < Test::Unit::TestCase end end end - - context "A multipage PDF" do - setup do - @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb') - end - - teardown { @file.close } - - should "start with two pages with dimensions 612x792" do - cmd = %Q[identify -format "%wx%h" "#{@file.path}"] - assert_equal "612x792"*2, `#{cmd}`.chomp - end - - context "being thumbnailed at 100x100 with cropping" do - setup do - @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png) - end - - should "report its correct current and target geometries" do - assert_equal "100x100#", @thumb.target_geometry.to_s - assert_equal "612x792", @thumb.current_geometry.to_s - end - - should "report its correct format" do - assert_equal :png, @thumb.format - end - - should "create the thumbnail when sent #make" do - dst = @thumb.make - assert_match /100x100/, `identify "#{dst.path}"` - end - end - end end