Sha256: 2afa02ca8a7f5435e5af204364f798d4e46660f7b107a3849c4277db28a0b9f2

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require "test_helper"

module Fogged
  module Resources
    class AWSThumbnailJobTest < ActiveSupport::TestCase
      def setup
        super
        @resource = fogged_resources(:resource_thumbnail)
        Fogged.thumbnail_sizes = %w(50x50 100x100)
      end

      test "should thumbnail the image" do
        in_a_fork do
          require "mini_magick"
          Rails.application.config.active_job.queue_adapter = :delayed_job
          Fogged.configure

          Resource.any_instance.expects(:url).twice.returns("http://lorempixel.com/800/600/cats")

          AWSThumbnailJob.perform_now(@resource)

          Fogged.thumbnail_sizes.each_with_index do |size, index|
            key = @resource.send(:fogged_name_for, :thumbnails, index)
            f = Fogged.resources.files.get(key)
            Tempfile.open(["thumbnail", ".png"]) do |t|
              t.write(f.body)
              t.flush
              output_size = FastImage.size(t.path)
              assert_equal size, "#{output_size.first}x#{output_size.second}"
            end
          end
          refute @resource.encoding?
          assert_equal 100, @resource.reload.encoding_progress
        end
      end

      test "should not thumbnail with unknown image" do
        in_a_fork do
          require "mini_magick"
          Rails.application.config.active_job.queue_adapter = :delayed_job
          Fogged.configure

          Resource.any_instance.expects(:url).returns("http://localhost:7777/image")

          assert_raise(MiniMagick::Error) do
            AWSThumbnailJob.perform_now(@resource)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fogged-0.0.6 test/jobs/fogged/resources/aws_thumbnail_job_test.rb
fogged-0.0.5 test/jobs/fogged/resources/aws_thumbnail_job_test.rb