Skip to content

Instantly share code, notes, and snippets.

@mariovisic
Created May 8, 2011 12:19
Show Gist options
  • Save mariovisic/961335 to your computer and use it in GitHub Desktop.
Save mariovisic/961335 to your computer and use it in GitHub Desktop.
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
version :thumb do
process :resize_to_fill => [200, 150]
end
end
class PostImage < ActiveRecord::Base
mount_uploader :image, ImageUploader
validates :image, :presence => true
validates_integrity_of :image
validates_processing_of :image
attr_accessible :image
end
require 'spec_helper'
describe PostImage do
include CarrierWave::Test::Matchers
context 'without processing' do
before :all do
ImageUploader.enable_processing = false # Commenting out this line causes the test to pass!
@post_image = PostImage.create!(:image => File.open(Rails.root.join('spec', 'support', 'test_image.png')))
end
it 'should create an image' do
@post_image.image.should be_present
end
end
context 'with processing' do
before :all do
ImageUploader.enable_processing = true
@post_image = PostImage.create!(:image => File.open(Rails.root.join('spec', 'support', 'test_image.png')))
end
context 'resizing' do
it 'should create a thumbnail with dimensions 200x150' do
# Fails with expected "..../thumb_test_image.png" to have an exact size of 200 by 150, but it was 707 by 450.
@post_image.image.thumb.should have_dimensions(200, 150)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment