1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
require 'spec_helper'
describe CarrierWave::Uploader do
let(:uploader_class) { Class.new(CarrierWave::Uploader::Base) }
let(:uploader) { uploader_class.new }
after { FileUtils.rm_rf(public_path) }
describe 'with a default url' do
before do
uploader_class.class_eval do
version :thumb
def default_url
['http://someurl.example.com', version_name].compact.join('/')
end
end
end
describe '#blank?' do
subject { uploader }
it "is blank by default" do
is_expected.to be_blank
end
end
describe '#current_path' do
subject { uploader.current_path }
it { is_expected.to be_nil }
end
describe '#url' do
let(:url_example) { "http://someurl.example.com" }
it "returns the default url" do
expect(uploader.url).to eq(url_example)
end
it "returns the default url with version when given" do
expect(uploader.url(:thumb)).to eq("#{url_example}/thumb")
end
end
describe '#cache!' do
let(:cache_id) { '1369894322-345-1234-2255' }
let(:file_name) { 'test.jpg' }
subject { uploader }
before do
allow(CarrierWave).to receive(:generate_cache_id).and_return(cache_id)
uploader.cache!(File.open(file_path(file_name)))
end
it "caches a file" do
expect(uploader.file).to be_an_instance_of(CarrierWave::SanitizedFile)
end
it "is cached" do
expect(uploader).to be_cached
end
it "isn't blank" do
expect(uploader).not_to be_blank
end
it "sets the current_path" do
expect(uploader.current_path).to eq(public_path("uploads/tmp/#{cache_id}/#{file_name}"))
end
it "sets the url" do
expect(uploader.url).to eq ("/uploads/tmp/#{cache_id}/#{file_name}")
end
end
end
end
|