carrierwave 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of carrierwave might be problematic. Click here for more details.
- data/README.rdoc +33 -15
- data/lib/carrierwave.rb +0 -1
- data/lib/carrierwave/compatibility/paperclip.rb +2 -2
- data/lib/carrierwave/orm/activerecord.rb +9 -5
- data/lib/carrierwave/orm/datamapper.rb +10 -0
- data/lib/carrierwave/processing/mini_magick.rb +1 -1
- data/lib/carrierwave/processing/rmagick.rb +4 -4
- data/lib/carrierwave/sanitized_file.rb +2 -2
- data/lib/carrierwave/storage/cloud_files.rb +11 -12
- data/lib/carrierwave/storage/grid_fs.rb +37 -26
- data/lib/carrierwave/storage/right_s3.rb +1 -168
- data/lib/carrierwave/storage/s3.rb +73 -66
- data/lib/carrierwave/test/matchers.rb +57 -21
- data/lib/carrierwave/uploader/configuration.rb +8 -5
- data/lib/carrierwave/uploader/processing.rb +1 -0
- data/lib/carrierwave/uploader/url.rb +2 -2
- data/lib/carrierwave/uploader/versions.rb +10 -0
- metadata +31 -279
- data/Generators +0 -4
- data/History.txt +0 -125
- data/Manifest.txt +0 -111
- data/Rakefile +0 -39
- data/carrierwave.gemspec +0 -85
- data/cucumber.yml +0 -2
- data/features/caching.feature +0 -28
- data/features/download.feature +0 -20
- data/features/file_storage.feature +0 -37
- data/features/file_storage_overridden_filename.feature +0 -38
- data/features/file_storage_overridden_store_dir.feature +0 -38
- data/features/file_storage_reversing_processor.feature +0 -43
- data/features/fixtures/bork.txt +0 -1
- data/features/fixtures/monkey.txt +0 -1
- data/features/grid_fs_storage.feature +0 -32
- data/features/mount_activerecord.feature +0 -46
- data/features/mount_datamapper.feature +0 -46
- data/features/step_definitions/activerecord_steps.rb +0 -22
- data/features/step_definitions/caching_steps.rb +0 -14
- data/features/step_definitions/datamapper_steps.rb +0 -29
- data/features/step_definitions/download_steps.rb +0 -4
- data/features/step_definitions/file_steps.rb +0 -53
- data/features/step_definitions/general_steps.rb +0 -85
- data/features/step_definitions/mount_steps.rb +0 -19
- data/features/step_definitions/store_steps.rb +0 -18
- data/features/support/activerecord.rb +0 -30
- data/features/support/datamapper.rb +0 -7
- data/features/support/env.rb +0 -22
- data/features/versions_basics.feature +0 -50
- data/features/versions_nested_versions.feature +0 -70
- data/features/versions_overridden_filename.feature +0 -51
- data/features/versions_overriden_store_dir.feature +0 -41
- data/lib/carrierwave/orm/mongomapper.rb +0 -27
- data/merb_generators/uploader_generator.rb +0 -22
- data/rails_generators/uploader/USAGE +0 -2
- data/rails_generators/uploader/templates/uploader.rb +0 -47
- data/rails_generators/uploader/uploader_generator.rb +0 -21
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/compatibility/paperclip_spec.rb +0 -52
- data/spec/fixtures/bork.txt +0 -1
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/fixtures/portrait.jpg +0 -0
- data/spec/fixtures/test.jpeg +0 -1
- data/spec/fixtures/test.jpg +0 -1
- data/spec/mount_spec.rb +0 -538
- data/spec/orm/activerecord_spec.rb +0 -271
- data/spec/orm/datamapper_spec.rb +0 -168
- data/spec/orm/mongoid_spec.rb +0 -202
- data/spec/orm/mongomapper_spec.rb +0 -202
- data/spec/orm/sequel_spec.rb +0 -183
- data/spec/processing/image_science_spec.rb +0 -56
- data/spec/processing/mini_magick_spec.rb +0 -76
- data/spec/processing/rmagick_spec.rb +0 -75
- data/spec/sanitized_file_spec.rb +0 -623
- data/spec/spec_helper.rb +0 -92
- data/spec/storage/cloudfiles_spec.rb +0 -78
- data/spec/storage/grid_fs_spec.rb +0 -83
- data/spec/storage/right_s3_spec.rb +0 -83
- data/spec/storage/s3_spec.rb +0 -95
- data/spec/uploader/cache_spec.rb +0 -209
- data/spec/uploader/configuration_spec.rb +0 -105
- data/spec/uploader/default_url_spec.rb +0 -85
- data/spec/uploader/download_spec.rb +0 -75
- data/spec/uploader/extension_whitelist_spec.rb +0 -44
- data/spec/uploader/mountable_spec.rb +0 -33
- data/spec/uploader/paths_spec.rb +0 -22
- data/spec/uploader/processing_spec.rb +0 -73
- data/spec/uploader/proxy_spec.rb +0 -54
- data/spec/uploader/remove_spec.rb +0 -70
- data/spec/uploader/store_spec.rb +0 -264
- data/spec/uploader/url_spec.rb +0 -102
- data/spec/uploader/versions_spec.rb +0 -298
data/spec/spec_helper.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
$TESTING=true
|
4
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
|
8
|
-
require 'tempfile'
|
9
|
-
#require 'ruby-debug'
|
10
|
-
require 'spec'
|
11
|
-
require 'spec/autorun'
|
12
|
-
|
13
|
-
require 'carrierwave'
|
14
|
-
require 'timecop'
|
15
|
-
require 'time'
|
16
|
-
require 'json'
|
17
|
-
|
18
|
-
require 'logger'
|
19
|
-
|
20
|
-
alias :running :lambda
|
21
|
-
|
22
|
-
def file_path( *paths )
|
23
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
24
|
-
end
|
25
|
-
|
26
|
-
def public_path( *paths )
|
27
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
|
28
|
-
end
|
29
|
-
|
30
|
-
CarrierWave.root = public_path
|
31
|
-
|
32
|
-
module CarrierWave
|
33
|
-
module Test
|
34
|
-
module MockStorage
|
35
|
-
def mock_storage(kind)
|
36
|
-
storage = mock("storage for #{kind} uploader")
|
37
|
-
storage.stub!(:setup!)
|
38
|
-
storage
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
module MockFiles
|
43
|
-
def stub_merb_tempfile(filename)
|
44
|
-
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
45
|
-
|
46
|
-
t = Tempfile.new(filename)
|
47
|
-
FileUtils.copy_file(file_path(filename), t.path)
|
48
|
-
|
49
|
-
return t
|
50
|
-
end
|
51
|
-
|
52
|
-
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
53
|
-
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
54
|
-
|
55
|
-
t = Tempfile.new(filename)
|
56
|
-
FileUtils.copy_file(file_path(filename), t.path)
|
57
|
-
|
58
|
-
# This is stupid, but for some reason rspec won't play nice...
|
59
|
-
eval <<-EOF
|
60
|
-
def t.original_filename; '#{fake_name || filename}'; end
|
61
|
-
def t.content_type; '#{mime_type}'; end
|
62
|
-
def t.local_path; path; end
|
63
|
-
EOF
|
64
|
-
|
65
|
-
return t
|
66
|
-
end
|
67
|
-
|
68
|
-
def stub_stringio(filename, mime_type=nil, fake_name=nil)
|
69
|
-
if filename
|
70
|
-
t = StringIO.new( IO.read( file_path( filename ) ) )
|
71
|
-
else
|
72
|
-
t = StringIO.new
|
73
|
-
end
|
74
|
-
t.stub!(:local_path).and_return("")
|
75
|
-
t.stub!(:original_filename).and_return(filename || fake_name)
|
76
|
-
t.stub!(:content_type).and_return(mime_type)
|
77
|
-
return t
|
78
|
-
end
|
79
|
-
|
80
|
-
def stub_file(filename, mime_type=nil, fake_name=nil)
|
81
|
-
f = File.open(file_path(filename))
|
82
|
-
return f
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
Spec::Runner.configure do |config|
|
89
|
-
config.include CarrierWave::Test::Matchers
|
90
|
-
config.include CarrierWave::Test::MockFiles
|
91
|
-
config.include CarrierWave::Test::MockStorage
|
92
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
5
|
-
if ENV['CLOUDFILES_SPEC']
|
6
|
-
require 'cloudfiles'
|
7
|
-
require 'net/http'
|
8
|
-
|
9
|
-
describe CarrierWave::Storage::CloudFiles do
|
10
|
-
before do
|
11
|
-
@uploader = mock('an uploader')
|
12
|
-
@uploader.stub!(:cloud_files_username).and_return(ENV["CLOUD_FILES_USER_NAME"])
|
13
|
-
@uploader.stub!(:cloud_files_api_key).and_return(ENV["CLOUD_FILES_API_KEY"])
|
14
|
-
@uploader.stub!(:cloud_files_container).and_return(ENV['CARRIERWAVE_TEST_CONTAINER'])
|
15
|
-
@storage = CarrierWave::Storage::CloudFiles.new(@uploader)
|
16
|
-
@file = stub_tempfile('test.jpg', 'application/xml')
|
17
|
-
|
18
|
-
@cf = CloudFiles::Connection.new(ENV["CLOUD_FILES_USER_NAME"], ENV["CLOUD_FILES_API_KEY"])
|
19
|
-
@container = @cf.container(@uploader.cloud_files_container)
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#store!' do
|
23
|
-
before do
|
24
|
-
@uploader.stub!(:store_path).and_return('uploads/bar.txt')
|
25
|
-
@cloud_file = @storage.store!(@file)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should upload the file to Cloud Files" do
|
29
|
-
@container.object('uploads/bar.txt').data.should == 'this is stuff'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should have a path" do
|
33
|
-
@cloud_file.path.should == 'uploads/bar.txt'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should have an Rackspace URL" do
|
37
|
-
@cloud_file.url.should =~ %r!http://(.*?).cdn.cloudfiles.rackspacecloud.com/uploads/bar.txt!
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should store the content type on Cloud Files" do
|
41
|
-
@cloud_file.content_type.should == 'application/xml'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should be deletable" do
|
45
|
-
@cloud_file.delete
|
46
|
-
@container.object_exists?('uploads/bar.txt').should be_false
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#retrieve!' do
|
52
|
-
before do
|
53
|
-
@container.create_object('uploads/bar.txt').write("A test, 1234")
|
54
|
-
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
55
|
-
|
56
|
-
@cloud_file = @storage.retrieve!('bar.txt')
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should retrieve the file contents from Cloud Files" do
|
60
|
-
@cloud_file.read.chomp.should == "A test, 1234"
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should have a path" do
|
64
|
-
@cloud_file.path.should == 'uploads/bar.txt'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should have an Rackspace URL" do
|
68
|
-
@cloud_file.url.should =~ %r!http://(.*?).cdn.cloudfiles.rackspacecloud.com/uploads/bar.txt!
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should be deletable" do
|
72
|
-
@cloud_file.delete
|
73
|
-
@container.object_exists?('uploads/bar.txt').should be_false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
@@ -1,83 +0,0 @@
|
|
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', 27017).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_port).and_return(27017)
|
13
|
-
@uploader.stub!(:grid_fs_access_url).and_return(nil)
|
14
|
-
@uploader.stub!(:grid_fs_username).and_return(nil)
|
15
|
-
@uploader.stub!(:grid_fs_password).and_return(nil)
|
16
|
-
|
17
|
-
@storage = CarrierWave::Storage::GridFS.new(@uploader)
|
18
|
-
@file = stub_tempfile('test.jpg', 'application/xml')
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
GridFS::GridStore.unlink(@database, 'uploads/bar.txt')
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#store!' do
|
26
|
-
before do
|
27
|
-
@uploader.stub!(:store_path).and_return('uploads/bar.txt')
|
28
|
-
@grid_fs_file = @storage.store!(@file)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should upload the file to gridfs" do
|
32
|
-
GridFS::GridStore.read(@database, 'uploads/bar.txt').should == 'this is stuff'
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should not have a path" do
|
36
|
-
@grid_fs_file.path.should be_nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should not have a URL" do
|
40
|
-
@grid_fs_file.url.should be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be deletable" do
|
44
|
-
@grid_fs_file.delete
|
45
|
-
GridFS::GridStore.read(@database, 'uploads/bar.txt').should == ''
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should store the content type on GridFS" do
|
49
|
-
@grid_fs_file.content_type.should == 'application/xml'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#retrieve!' do
|
54
|
-
before do
|
55
|
-
GridFS::GridStore.open(@database, 'uploads/bar.txt', 'w') { |f| f.puts "A test, 1234" }
|
56
|
-
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
57
|
-
@grid_fs_file = @storage.retrieve!('bar.txt')
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should retrieve the file contents from gridfs" do
|
61
|
-
@grid_fs_file.read.chomp.should == "A test, 1234"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not have a path" do
|
65
|
-
@grid_fs_file.path.should be_nil
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not have a URL unless set" do
|
69
|
-
@grid_fs_file.url.should be_nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should return a URL if configured" do
|
73
|
-
@uploader.stub!(:grid_fs_access_url).and_return("/image/show")
|
74
|
-
@grid_fs_file.url.should == "/image/show/uploads/bar.txt"
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should be deletable" do
|
78
|
-
@grid_fs_file.delete
|
79
|
-
GridFS::GridStore.read(@database, 'uploads/bar.txt').should == ''
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
@@ -1,83 +0,0 @@
|
|
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
|
-
context "with cnamed bucket" do
|
44
|
-
it "should have a CNAMED URL" do
|
45
|
-
@uploader.stub!(:s3_cnamed).and_return(true)
|
46
|
-
@uploader.stub!(:s3_bucket).and_return('foo.bar')
|
47
|
-
@s3_file.url.should == 'http://foo.bar/uploads/bar.txt'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should be deletable" do
|
52
|
-
@s3_file.delete
|
53
|
-
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#retrieve!' do
|
58
|
-
before do
|
59
|
-
@storage.connection.put(@bucket, "uploads/bar.txt", "A test, 1234", {'a-amz-acl' => 'public-read'})
|
60
|
-
@uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
61
|
-
@s3_file = @storage.retrieve!('bar.txt')
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should retrieve the file contents from s3" do
|
65
|
-
@s3_file.read.chomp.should == "A test, 1234"
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should have a path" do
|
69
|
-
@s3_file.path.should == 'uploads/bar.txt'
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should have an Amazon URL" do
|
73
|
-
@s3_file.url.should == "http://#{@bucket}.s3.amazonaws.com/uploads/bar.txt"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should be deletable" do
|
77
|
-
@s3_file.delete
|
78
|
-
lambda {@storage.connection.head(@bucket, 'uploads/bar.txt')}.should raise_error(RightAws::AwsError)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
data/spec/storage/s3_spec.rb
DELETED
@@ -1,95 +0,0 @@
|
|
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
|
data/spec/uploader/cache_spec.rb
DELETED
@@ -1,209 +0,0 @@
|
|
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
|