Sha256: b0e21cd5c4d03a938e340c94a9b468eb1775659deb541070b71f083119244a3f

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe "Processing image attachments" do
  use_model_class(:Thing,
                  :width => :integer,
                  :height => :integer)

  def identify
    Bulldog::Processor::ImageMagick.identify_path
  end

  before do
    tmp = temporary_directory
    Thing.has_attachment :photo do
      path "#{tmp}/:id.:style.png"
      style :small, {:size => '10x10!'}
      style :large, {:size => '1000x1000!'}

      process :before => :save do
        width, height = dimensions
        record.width = width
        record.height = height
      end

      process :on => :resize do
        resize
      end
    end
    @thing = Thing.new
    @thing.stubs(:id).returns(5)
    @file = uploaded_file('test-40x30.jpg')
  end

  after do
    @file.close
  end

  def path(style)
    "#{temporary_directory}/5.#{style}.png"
  end

  it "should run the after_save process after saving" do
    @thing.update_attributes(:photo => @file)
    @thing.width.should == 40
    @thing.height.should == 30
  end

  it "should process the attachment when the processor is run" do
    File.exist?(path(:original)).should be_false
    File.exist?(path(:small)).should be_false
    File.exist?(path(:large)).should be_false

    @thing.update_attributes(:photo => @file).should be_true
    @thing.process_attachment(:photo, :resize)

    `"#{identify}" -format "%w %h" "#{path(:original)}"`.chomp.should == '40 30'
    `"#{identify}" -format "%w %h" "#{path(:small)}"`.chomp.should == '10 10'
    `"#{identify}" -format "%w %h" "#{path(:large)}"`.chomp.should == '1000 1000'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bulldog-0.2.4 spec/integration/processing_image_attachments.rb
bulldog-0.2.3 spec/integration/processing_image_attachments.rb
bulldog-0.2.2 spec/integration/processing_image_attachments.rb
bulldog-0.2.1 spec/integration/processing_image_attachments.rb
bulldog-0.2.0 spec/integration/processing_image_attachments.rb