Created
October 19, 2010 08:43
-
-
Save fbjork/633857 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::MiniMagick | |
process :convert => 'png' | |
process :resize_to_fit => [600, 600] | |
version :thumb do | |
process :convert => 'png' | |
process :resize_to_fill => [100, 100] | |
end | |
version :tiny do | |
process :convert => 'png' | |
process :resize_to_fill => [45, 45] | |
end | |
def cache_dir | |
"#{Rails.root}/tmp/uploads" | |
end | |
def extension_white_list | |
%w(jpg jpeg gif png bmp) | |
end | |
def filename | |
"#{mounted_as}.png" | |
end | |
def max_file_size | |
5242880 | |
end | |
def store_dir | |
"#{model.class.to_s.downcase.pluralize}/#{model.username}" | |
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
require 'spec_helper' | |
include CarrierWave::Test::Matchers | |
describe ImageUploader do | |
before :all do | |
@user = Factory(:user) | |
ImageUploader.enable_processing = true | |
@uploader = ImageUploader.new(@user, :avatar) | |
@uploader.store!(File.open("#{Rails.root}/features/files/thumb_avatar.jpg")) | |
end | |
after :all do | |
@uploader.remove! | |
ImageUploader.enable_processing = false | |
end | |
describe 'the large version' do | |
it "should scale down a landscape image to fit within 600 by 600 pixels" do | |
@uploader.should be_no_larger_than(600, 600) | |
end | |
end | |
describe 'the thumb version' do | |
it "should scale down a landscape image to be exactly 100 by 100 pixels" do | |
@uploader.thumb.should have_dimensions(100, 100) | |
end | |
end | |
describe 'the tiny version' do | |
it "should scale down a landscape image to be exactly 45 by 45 pixels" do | |
@uploader.tiny.should have_dimensions(45, 45) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment