Created
May 8, 2011 12:19
-
-
Save mariovisic/961335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageUploader < CarrierWave::Uploader::Base | |
include CarrierWave::RMagick | |
storage :file | |
version :thumb do | |
process :resize_to_fill => [200, 150] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostImage < ActiveRecord::Base | |
mount_uploader :image, ImageUploader | |
validates :image, :presence => true | |
validates_integrity_of :image | |
validates_processing_of :image | |
attr_accessible :image | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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