dsturnbull-carrierwave 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Generators +4 -0
- data/History.txt +118 -0
- data/Manifest.txt +107 -0
- data/README.rdoc +502 -0
- data/Rakefile +38 -0
- data/cucumber.yml +2 -0
- data/features/caching.feature +28 -0
- data/features/download.feature +20 -0
- data/features/file_storage.feature +37 -0
- data/features/file_storage_overridden_filename.feature +38 -0
- data/features/file_storage_overridden_store_dir.feature +38 -0
- data/features/file_storage_reversing_processor.feature +43 -0
- data/features/fixtures/bork.txt +1 -0
- data/features/fixtures/monkey.txt +1 -0
- data/features/grid_fs_storage.feature +32 -0
- data/features/mount_activerecord.feature +46 -0
- data/features/mount_datamapper.feature +46 -0
- data/features/step_definitions/activerecord_steps.rb +22 -0
- data/features/step_definitions/caching_steps.rb +14 -0
- data/features/step_definitions/datamapper_steps.rb +29 -0
- data/features/step_definitions/download_steps.rb +4 -0
- data/features/step_definitions/file_steps.rb +53 -0
- data/features/step_definitions/general_steps.rb +85 -0
- data/features/step_definitions/mount_steps.rb +19 -0
- data/features/step_definitions/store_steps.rb +18 -0
- data/features/support/activerecord.rb +30 -0
- data/features/support/datamapper.rb +7 -0
- data/features/support/env.rb +22 -0
- data/features/versions_basics.feature +50 -0
- data/features/versions_nested_versions.feature +70 -0
- data/features/versions_overridden_filename.feature +51 -0
- data/features/versions_overriden_store_dir.feature +41 -0
- data/lib/carrierwave/compatibility/paperclip.rb +95 -0
- data/lib/carrierwave/core_ext/blank.rb +46 -0
- data/lib/carrierwave/core_ext/inheritable_attributes.rb +104 -0
- data/lib/carrierwave/core_ext/module_setup.rb +51 -0
- data/lib/carrierwave/mount.rb +359 -0
- data/lib/carrierwave/orm/activerecord.rb +73 -0
- data/lib/carrierwave/orm/datamapper.rb +27 -0
- data/lib/carrierwave/orm/mongoid.rb +23 -0
- data/lib/carrierwave/orm/mongomapper.rb +27 -0
- data/lib/carrierwave/orm/sequel.rb +45 -0
- data/lib/carrierwave/processing/image_science.rb +101 -0
- data/lib/carrierwave/processing/mini_magick.rb +269 -0
- data/lib/carrierwave/processing/rmagick.rb +282 -0
- data/lib/carrierwave/sanitized_file.rb +268 -0
- data/lib/carrierwave/storage/abstract.rb +30 -0
- data/lib/carrierwave/storage/file.rb +48 -0
- data/lib/carrierwave/storage/grid_fs.rb +96 -0
- data/lib/carrierwave/storage/right_s3.rb +170 -0
- data/lib/carrierwave/storage/s3.rb +199 -0
- data/lib/carrierwave/test/matchers.rb +128 -0
- data/lib/carrierwave/uploader/cache.rb +145 -0
- data/lib/carrierwave/uploader/callbacks.rb +42 -0
- data/lib/carrierwave/uploader/configuration.rb +122 -0
- data/lib/carrierwave/uploader/default_url.rb +19 -0
- data/lib/carrierwave/uploader/download.rb +59 -0
- data/lib/carrierwave/uploader/extension_whitelist.rb +37 -0
- data/lib/carrierwave/uploader/mountable.rb +39 -0
- data/lib/carrierwave/uploader/processing.rb +83 -0
- data/lib/carrierwave/uploader/proxy.rb +62 -0
- data/lib/carrierwave/uploader/remove.rb +22 -0
- data/lib/carrierwave/uploader/store.rb +89 -0
- data/lib/carrierwave/uploader/url.rb +24 -0
- data/lib/carrierwave/uploader/versions.rb +146 -0
- data/lib/carrierwave/uploader.rb +44 -0
- data/lib/carrierwave.rb +96 -0
- data/merb_generators/uploader_generator.rb +22 -0
- data/rails_generators/uploader/USAGE +2 -0
- data/rails_generators/uploader/templates/uploader.rb +47 -0
- data/rails_generators/uploader/uploader_generator.rb +21 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/compatibility/paperclip_spec.rb +52 -0
- data/spec/fixtures/bork.txt +1 -0
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/fixtures/test.jpeg +1 -0
- data/spec/fixtures/test.jpg +1 -0
- data/spec/mount_spec.rb +538 -0
- data/spec/orm/activerecord_spec.rb +271 -0
- data/spec/orm/datamapper_spec.rb +168 -0
- data/spec/orm/mongoid_spec.rb +206 -0
- data/spec/orm/mongomapper_spec.rb +202 -0
- data/spec/orm/sequel_spec.rb +183 -0
- data/spec/processing/image_science_spec.rb +56 -0
- data/spec/processing/mini_magick_spec.rb +76 -0
- data/spec/processing/rmagick_spec.rb +75 -0
- data/spec/sanitized_file_spec.rb +601 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/storage/grid_fs_spec.rb +82 -0
- data/spec/storage/right_s3_spec.rb +75 -0
- data/spec/storage/s3_spec.rb +95 -0
- data/spec/uploader/cache_spec.rb +209 -0
- data/spec/uploader/configuration_spec.rb +105 -0
- data/spec/uploader/default_url_spec.rb +85 -0
- data/spec/uploader/download_spec.rb +75 -0
- data/spec/uploader/extension_whitelist_spec.rb +44 -0
- data/spec/uploader/mountable_spec.rb +33 -0
- data/spec/uploader/paths_spec.rb +22 -0
- data/spec/uploader/processing_spec.rb +73 -0
- data/spec/uploader/proxy_spec.rb +54 -0
- data/spec/uploader/remove_spec.rb +70 -0
- data/spec/uploader/store_spec.rb +248 -0
- data/spec/uploader/url_spec.rb +87 -0
- data/spec/uploader/versions_spec.rb +298 -0
- metadata +351 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::Storage::GridFS do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@database = Mongo::Connection.new('localhost').db('carrierwave_test')
|
9
|
+
@uploader = mock('an uploader')
|
10
|
+
@uploader.stub!(:grid_fs_database).and_return("carrierwave_test")
|
11
|
+
@uploader.stub!(:grid_fs_host).and_return("localhost")
|
12
|
+
@uploader.stub!(:grid_fs_access_url).and_return(nil)
|
13
|
+
@uploader.stub!(:grid_fs_username).and_return(nil)
|
14
|
+
@uploader.stub!(:grid_fs_password).and_return(nil)
|
15
|
+
|
16
|
+
@storage = CarrierWave::Storage::GridFS.new(@uploader)
|
17
|
+
@file = stub_tempfile('test.jpg', 'application/xml')
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
GridFS::GridStore.unlink(@database, 'uploads/bar.txt')
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#store!' do
|
25
|
+
before do
|
26
|
+
@uploader.stub!(:store_path).and_return('uploads/bar.txt')
|
27
|
+
@grid_fs_file = @storage.store!(@file)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should upload the file to gridfs" do
|
31
|
+
GridFS::GridStore.read(@database, 'uploads/bar.txt').should == 'this is stuff'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not have a path" do
|
35
|
+
@grid_fs_file.path.should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not have a URL" do
|
39
|
+
@grid_fs_file.url.should be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be deletable" do
|
43
|
+
@grid_fs_file.delete
|
44
|
+
GridFS::GridStore.read(@database, 'uploads/bar.txt').should == ''
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should store the content type on GridFS" do
|
48
|
+
@grid_fs_file.content_type.should == 'application/xml'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#retrieve!' do
|
53
|
+
before do
|
54
|
+
GridFS::GridStore.open(@database, 'uploads/bar.txt', 'w') { |f| f.puts "A test, 1234" }
|
55
|
+
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
56
|
+
@grid_fs_file = @storage.retrieve!('bar.txt')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should retrieve the file contents from gridfs" do
|
60
|
+
@grid_fs_file.read.chomp.should == "A test, 1234"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not have a path" do
|
64
|
+
@grid_fs_file.path.should be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not have a URL unless set" do
|
68
|
+
@grid_fs_file.url.should be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return a URL if configured" do
|
72
|
+
@uploader.stub!(:grid_fs_access_url).and_return("/image/show")
|
73
|
+
@grid_fs_file.url.should == "/image/show/uploads/bar.txt"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be deletable" do
|
77
|
+
@grid_fs_file.delete
|
78
|
+
GridFS::GridStore.read(@database, 'uploads/bar.txt').should == ''
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
require 'right_aws'
|
5
|
+
|
6
|
+
if ENV['S3_SPEC']
|
7
|
+
describe CarrierWave::Storage::RightS3 do
|
8
|
+
before do
|
9
|
+
@bucket = ENV['CARRIERWAVE_TEST_BUCKET']
|
10
|
+
@uploader = mock('an uploader')
|
11
|
+
@uploader.stub!(:s3_access_key_id).and_return(ENV["S3_ACCESS_KEY_ID"])
|
12
|
+
@uploader.stub!(:s3_secret_access_key).and_return(ENV["S3_SECRET_ACCESS_KEY"])
|
13
|
+
@uploader.stub!(:s3_bucket).and_return(@bucket)
|
14
|
+
@uploader.stub!(:s3_access_policy).and_return('public-read')
|
15
|
+
@uploader.stub!(:s3_cnamed).and_return(false)
|
16
|
+
|
17
|
+
@storage = CarrierWave::Storage::RightS3.new(@uploader)
|
18
|
+
@file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
@storage.connection.delete(@bucket, 'uploads/bar.txt')
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#store!' do
|
26
|
+
before do
|
27
|
+
@uploader.stub!(:store_path).and_return('uploads/bar.txt')
|
28
|
+
@s3_file = @storage.store!(@file)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should upload the file to s3" do
|
32
|
+
@storage.connection.get_object(@bucket, 'uploads/bar.txt').should == 'this is stuff'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have a path" do
|
36
|
+
@s3_file.path.should == 'uploads/bar.txt'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have an Amazon URL" do
|
40
|
+
@s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be deletable" do
|
44
|
+
@s3_file.delete
|
45
|
+
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#retrieve!' do
|
50
|
+
before do
|
51
|
+
@storage.connection.put(@bucket, "uploads/bar.txt", "A test, 1234", {'a-amz-acl' => 'public-read'})
|
52
|
+
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
53
|
+
@s3_file = @storage.retrieve!('bar.txt')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should retrieve the file contents from s3" do
|
57
|
+
@s3_file.read.chomp.should == "A test, 1234"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have a path" do
|
61
|
+
@s3_file.path.should == 'uploads/bar.txt'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have an Amazon URL" do
|
65
|
+
@s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be deletable" do
|
69
|
+
@s3_file.delete
|
70
|
+
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
require 'aws/s3'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
if ENV['S3_SPEC']
|
8
|
+
describe CarrierWave::Storage::S3 do
|
9
|
+
before do
|
10
|
+
@uploader = mock('an uploader')
|
11
|
+
@uploader.stub!(:s3_access_key_id).and_return(ENV["S3_ACCESS_KEY_ID"])
|
12
|
+
@uploader.stub!(:s3_secret_access_key).and_return(ENV["S3_SECRET_ACCESS_KEY"])
|
13
|
+
@uploader.stub!(:s3_bucket).and_return(ENV['CARRIERWAVE_TEST_BUCKET'])
|
14
|
+
@uploader.stub!(:s3_access).and_return(:public_read)
|
15
|
+
@uploader.stub!(:s3_cnamed).and_return(false)
|
16
|
+
@uploader.stub!(:s3_headers).and_return({'Expires' => 'Fri, 21 Jan 2021 16:51:06 GMT'})
|
17
|
+
|
18
|
+
@storage = CarrierWave::Storage::S3.new(@uploader)
|
19
|
+
@file = stub_tempfile('test.jpg', 'application/xml')
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
AWS::S3::S3Object.delete('uploads/bar.txt', @uploader.s3_bucket)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#store!' do
|
27
|
+
before do
|
28
|
+
@uploader.stub!(:store_path).and_return('uploads/bar.txt')
|
29
|
+
@s3_file = @storage.store!(@file)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should upload the file to s3" do
|
33
|
+
AWS::S3::S3Object.value('uploads/bar.txt', @uploader.s3_bucket).should == 'this is stuff'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a path" do
|
37
|
+
@s3_file.path.should == 'uploads/bar.txt'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have an Amazon URL" do
|
41
|
+
@s3_file.url.should == "http://s3.amazonaws.com/#{@uploader.s3_bucket}/uploads/bar.txt"
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with cnamed bucket" do
|
45
|
+
it "should have a CNAMED URL" do
|
46
|
+
@uploader.stub!(:s3_cnamed).and_return(true)
|
47
|
+
@uploader.stub!(:s3_bucket).and_return('foo.bar')
|
48
|
+
@s3_file.url.should == 'http://foo.bar/uploads/bar.txt'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be deletable" do
|
53
|
+
@s3_file.delete
|
54
|
+
AWS::S3::S3Object.exists?('uploads/bar.txt', @uploader.s3_bucket).should be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should store the content type on S3" do
|
58
|
+
@s3_file.content_type.should == 'application/xml'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set headers" do
|
62
|
+
client = Net::HTTP.new("s3.amazonaws.com")
|
63
|
+
headers = client.request_head(URI.parse(@s3_file.url).path)
|
64
|
+
headers['Expires'].should == 'Fri, 21 Jan 2021 16:51:06 GMT'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#retrieve!' do
|
69
|
+
before do
|
70
|
+
AWS::S3::S3Object.store('uploads/bar.txt', "A test, 1234", @uploader.s3_bucket)
|
71
|
+
|
72
|
+
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
73
|
+
@s3_file = @storage.retrieve!('bar.txt')
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should retrieve the file contents from s3" do
|
77
|
+
@s3_file.read.chomp.should == "A test, 1234"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should have a path" do
|
81
|
+
@s3_file.path.should == 'uploads/bar.txt'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have an Amazon URL" do
|
85
|
+
@s3_file.url.should == "http://s3.amazonaws.com/#{@uploader.s3_bucket}/uploads/bar.txt"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should be deletable" do
|
89
|
+
@s3_file.delete
|
90
|
+
AWS::S3::S3Object.exists?('uploads/bar.txt', @uploader.s3_bucket).should be_false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::Uploader do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
9
|
+
@uploader = @uploader_class.new
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
FileUtils.rm_rf(public_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.clean_cached_files!' do
|
17
|
+
before do
|
18
|
+
@cache_dir = File.expand_path(@uploader_class.cache_dir, CarrierWave.root)
|
19
|
+
FileUtils.mkdir_p File.expand_path('20071201-1234-234-2213', @cache_dir)
|
20
|
+
FileUtils.mkdir_p File.expand_path('20071203-1234-234-2213', @cache_dir)
|
21
|
+
FileUtils.mkdir_p File.expand_path('20071205-1234-234-2213', @cache_dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
after { FileUtils.rm_rf(@cache_dir) }
|
25
|
+
|
26
|
+
it "should clear all files older than 24 hours in the default cache directory" do
|
27
|
+
Timecop.freeze(Time.parse('2007-12-06 10:12')) do
|
28
|
+
@uploader_class.clean_cached_files!
|
29
|
+
end
|
30
|
+
Dir.glob("#{@cache_dir}/*").should have(1).element
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be aliased on the CarrierWave module" do
|
34
|
+
Timecop.freeze(Time.parse('2007-12-06 10:12')) do
|
35
|
+
CarrierWave.clean_cached_files!
|
36
|
+
end
|
37
|
+
Dir.glob("#{@cache_dir}/*").should have(1).element
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#cache_dir' do
|
42
|
+
it "should default to the config option" do
|
43
|
+
@uploader.cache_dir.should == 'uploads/tmp'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#cache!' do
|
48
|
+
|
49
|
+
before do
|
50
|
+
CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should cache a file" do
|
54
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
55
|
+
@uploader.file.should be_an_instance_of(CarrierWave::SanitizedFile)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be cached" do
|
59
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
60
|
+
@uploader.should be_cached
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should store the cache name" do
|
64
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
65
|
+
@uploader.cache_name.should == '20071201-1234-345-2255/test.jpg'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set the filename to the file's sanitized filename" do
|
69
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
70
|
+
@uploader.filename.should == 'test.jpg'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should move it to the tmp dir" do
|
74
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
75
|
+
@uploader.file.path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
|
76
|
+
@uploader.file.exists?.should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should set the url" do
|
80
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
81
|
+
@uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should raise an error when trying to cache a string" do
|
85
|
+
running {
|
86
|
+
@uploader.cache!(file_path('test.jpg'))
|
87
|
+
}.should raise_error(CarrierWave::FormNotMultipart)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should raise an error when trying to cache a pathname" do
|
91
|
+
running {
|
92
|
+
@uploader.cache!(Pathname.new(file_path('test.jpg')))
|
93
|
+
}.should raise_error(CarrierWave::FormNotMultipart)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should do nothing when trying to cache an empty file" do
|
97
|
+
@uploader.cache!(nil)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should set permissions if options are given" do
|
101
|
+
@uploader_class.permissions = 0777
|
102
|
+
|
103
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
104
|
+
@uploader.should have_permissions(0777)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#retrieve_from_cache!' do
|
109
|
+
it "should cache a file" do
|
110
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
111
|
+
@uploader.file.should be_an_instance_of(CarrierWave::SanitizedFile)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should be cached" do
|
115
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
116
|
+
@uploader.should be_cached
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should set the path to the tmp dir" do
|
120
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
121
|
+
@uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpeg')
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should overwrite a file that has already been cached" do
|
125
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
126
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/bork.txt')
|
127
|
+
@uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/bork.txt')
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should store the cache_name" do
|
131
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
132
|
+
@uploader.cache_name.should == '20071201-1234-345-2255/test.jpeg'
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should store the filename" do
|
136
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
137
|
+
@uploader.filename.should == 'test.jpeg'
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should set the url" do
|
141
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpeg')
|
142
|
+
@uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpeg'
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should raise an error when the cache_id has an invalid format" do
|
146
|
+
running {
|
147
|
+
@uploader.retrieve_from_cache!('12345/test.jpeg')
|
148
|
+
}.should raise_error(CarrierWave::InvalidParameter)
|
149
|
+
|
150
|
+
@uploader.file.should be_nil
|
151
|
+
@uploader.filename.should be_nil
|
152
|
+
@uploader.cache_name.should be_nil
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should raise an error when the original_filename contains invalid characters" do
|
156
|
+
running {
|
157
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/te/st.jpeg')
|
158
|
+
}.should raise_error(CarrierWave::InvalidParameter)
|
159
|
+
running {
|
160
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/te??%st.jpeg')
|
161
|
+
}.should raise_error(CarrierWave::InvalidParameter)
|
162
|
+
|
163
|
+
@uploader.file.should be_nil
|
164
|
+
@uploader.filename.should be_nil
|
165
|
+
@uploader.cache_name.should be_nil
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'with an overridden, reversing, filename' do
|
170
|
+
before do
|
171
|
+
@uploader_class.class_eval do
|
172
|
+
def filename
|
173
|
+
super.reverse unless super.blank?
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#cache!' do
|
179
|
+
|
180
|
+
before do
|
181
|
+
CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should set the filename to the file's reversed filename" do
|
185
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
186
|
+
@uploader.filename.should == "gpj.tset"
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should move it to the tmp dir with the filename unreversed" do
|
190
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
191
|
+
@uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
|
192
|
+
@uploader.file.exists?.should be_true
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#retrieve_from_cache!' do
|
197
|
+
it "should set the path to the tmp dir" do
|
198
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
|
199
|
+
@uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should set the filename to the reversed name of the file" do
|
203
|
+
@uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
|
204
|
+
@uploader.filename.should == "gpj.tset"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
|
6
|
+
describe CarrierWave do
|
7
|
+
before do
|
8
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.configure' do
|
12
|
+
it "should proxy to Uploader configuration" do
|
13
|
+
CarrierWave::Uploader::Base.add_config :test_config
|
14
|
+
CarrierWave.configure do |config|
|
15
|
+
config.test_config = "foo"
|
16
|
+
end
|
17
|
+
CarrierWave::Uploader::Base.test_config.should == 'foo'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe CarrierWave::Uploader::Base do
|
23
|
+
before do
|
24
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.configure' do
|
28
|
+
it "should set a configuration parameter" do
|
29
|
+
@uploader_class.add_config :foo_bar
|
30
|
+
@uploader_class.configure do |config|
|
31
|
+
config.foo_bar = "monkey"
|
32
|
+
end
|
33
|
+
@uploader_class.foo_bar.should == 'monkey'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".storage" do
|
38
|
+
it "should set the storage if an argument is given" do
|
39
|
+
storage = mock('some kind of storage')
|
40
|
+
@uploader_class.storage storage
|
41
|
+
@uploader_class.storage.should == storage
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should default to file" do
|
45
|
+
@uploader_class.storage.should == CarrierWave::Storage::File
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set the storage from the configured shortcuts if a symbol is given" do
|
49
|
+
@uploader_class.storage :file
|
50
|
+
@uploader_class.storage.should == CarrierWave::Storage::File
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should remember the storage when inherited" do
|
54
|
+
@uploader_class.storage :s3
|
55
|
+
subclass = Class.new(@uploader_class)
|
56
|
+
subclass.storage.should == CarrierWave::Storage::S3
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be changeable when inherited" do
|
60
|
+
@uploader_class.storage :s3
|
61
|
+
subclass = Class.new(@uploader_class)
|
62
|
+
subclass.storage.should == CarrierWave::Storage::S3
|
63
|
+
subclass.storage :file
|
64
|
+
subclass.storage.should == CarrierWave::Storage::File
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
describe '.add_config' do
|
70
|
+
it "should add a class level accessor" do
|
71
|
+
@uploader_class.add_config :foo_bar
|
72
|
+
@uploader_class.foo_bar = 'foo'
|
73
|
+
@uploader_class.foo_bar.should == 'foo'
|
74
|
+
end
|
75
|
+
|
76
|
+
['foo', :foo, 45, ['foo', :bar]].each do |val|
|
77
|
+
it "should be inheritable for a #{val.class}" do
|
78
|
+
@uploader_class.add_config :foo_bar
|
79
|
+
@child_class = Class.new(@uploader_class)
|
80
|
+
|
81
|
+
@uploader_class.foo_bar = val
|
82
|
+
@uploader_class.foo_bar.should == val
|
83
|
+
@child_class.foo_bar.should == val
|
84
|
+
|
85
|
+
@child_class.foo_bar = "bar"
|
86
|
+
@child_class.foo_bar.should == "bar"
|
87
|
+
|
88
|
+
@uploader_class.foo_bar.should == val
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
it "should add an instance level accessor" do
|
94
|
+
@uploader_class.add_config :foo_bar
|
95
|
+
@uploader_class.foo_bar = 'foo'
|
96
|
+
@uploader_class.new.foo_bar.should == 'foo'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should add a convenient in-class setter" do
|
100
|
+
@uploader_class.add_config :foo_bar
|
101
|
+
@uploader_class.foo_bar "monkey"
|
102
|
+
@uploader_class.foo_bar.should == "monkey"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe CarrierWave::Uploader do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@uploader_class = Class.new(CarrierWave::Uploader::Base)
|
9
|
+
@uploader = @uploader_class.new
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
FileUtils.rm_rf(public_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'with a default url' do
|
17
|
+
before do
|
18
|
+
@uploader_class.class_eval do
|
19
|
+
version :thumb
|
20
|
+
def default_url
|
21
|
+
["http://someurl.example.com", version_name].compact.join('/')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@uploader = @uploader_class.new
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#blank?' do
|
28
|
+
it "should be true by default" do
|
29
|
+
@uploader.should be_blank
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#current_path' do
|
34
|
+
it "should return nil" do
|
35
|
+
@uploader.current_path.should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#url' do
|
40
|
+
it "should return the default url" do
|
41
|
+
@uploader.url.should == 'http://someurl.example.com'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the default url with version when given" do
|
45
|
+
@uploader.url(:thumb).should == 'http://someurl.example.com/thumb'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#cache!' do
|
50
|
+
|
51
|
+
before do
|
52
|
+
CarrierWave.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should cache a file" do
|
56
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
57
|
+
@uploader.file.should be_an_instance_of(CarrierWave::SanitizedFile)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be cached" do
|
61
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
62
|
+
@uploader.should be_cached
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should no longer be blank" do
|
66
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
67
|
+
@uploader.should_not be_blank
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set the current_path" do
|
71
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
72
|
+
@uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should set the url" do
|
76
|
+
@uploader.cache!(File.open(file_path('test.jpg')))
|
77
|
+
@uploader.url.should_not == 'http://someurl.example.com'
|
78
|
+
@uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|