durran-carrierwave 0.3.2.3 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/Generators +1 -1
  2. data/History.txt +39 -2
  3. data/Manifest.txt +19 -5
  4. data/README.rdoc +180 -55
  5. data/Rakefile +11 -4
  6. data/features/grid_fs_storage.feature +32 -0
  7. data/features/step_definitions/general_steps.rb +6 -1
  8. data/features/support/activerecord.rb +1 -1
  9. data/features/support/env.rb +3 -16
  10. data/lib/carrierwave.rb +19 -74
  11. data/lib/carrierwave/compatibility/paperclip.rb +2 -2
  12. data/lib/carrierwave/core_ext/inheritable_attributes.rb +3 -3
  13. data/lib/carrierwave/mount.rb +36 -27
  14. data/lib/carrierwave/orm/activerecord.rb +3 -3
  15. data/lib/carrierwave/orm/datamapper.rb +2 -2
  16. data/lib/carrierwave/orm/mongoid.rb +23 -0
  17. data/lib/carrierwave/orm/mongomapper.rb +1 -1
  18. data/lib/carrierwave/orm/sequel.rb +4 -16
  19. data/lib/carrierwave/processing/image_science.rb +54 -25
  20. data/lib/carrierwave/processing/mini_magick.rb +269 -0
  21. data/lib/carrierwave/processing/rmagick.rb +4 -6
  22. data/lib/carrierwave/sanitized_file.rb +7 -6
  23. data/lib/carrierwave/storage/abstract.rb +0 -2
  24. data/lib/carrierwave/storage/file.rb +3 -5
  25. data/lib/carrierwave/storage/grid_fs.rb +92 -0
  26. data/lib/carrierwave/storage/right_s3.rb +183 -0
  27. data/lib/carrierwave/storage/s3.rb +37 -69
  28. data/lib/carrierwave/test/matchers.rb +22 -8
  29. data/lib/carrierwave/uploader.rb +2 -2
  30. data/lib/carrierwave/uploader/cache.rb +21 -18
  31. data/lib/carrierwave/uploader/configuration.rb +122 -0
  32. data/lib/carrierwave/uploader/default_url.rb +19 -0
  33. data/lib/carrierwave/uploader/processing.rb +4 -2
  34. data/lib/carrierwave/uploader/remove.rb +0 -1
  35. data/lib/carrierwave/uploader/store.rb +1 -68
  36. data/lib/carrierwave/uploader/url.rb +1 -1
  37. data/lib/carrierwave/uploader/versions.rb +3 -4
  38. data/{lib/generators → merb_generators}/uploader_generator.rb +0 -0
  39. data/rails_generators/uploader/templates/uploader.rb +4 -4
  40. data/spec/compatibility/paperclip_spec.rb +11 -2
  41. data/spec/fixtures/landscape.jpg +0 -0
  42. data/spec/fixtures/portrait.jpg +0 -0
  43. data/spec/mount_spec.rb +0 -25
  44. data/spec/orm/datamapper_spec.rb +55 -48
  45. data/spec/orm/mongoid_spec.rb +206 -0
  46. data/spec/orm/mongomapper_spec.rb +19 -1
  47. data/spec/orm/sequel_spec.rb +3 -12
  48. data/spec/processing/image_science_spec.rb +56 -0
  49. data/spec/processing/mini_magick_spec.rb +76 -0
  50. data/spec/processing/rmagick_spec.rb +68 -0
  51. data/spec/sanitized_file_spec.rb +84 -74
  52. data/spec/spec_helper.rb +1 -3
  53. data/spec/storage/grid_fs_spec.rb +78 -0
  54. data/spec/storage/right_s3_spec.rb +75 -0
  55. data/spec/storage/s3_spec.rb +83 -0
  56. data/spec/uploader/cache_spec.rb +1 -13
  57. data/spec/uploader/configuration_spec.rb +105 -0
  58. data/spec/uploader/{default_path_spec.rb → default_url_spec.rb} +22 -5
  59. data/spec/uploader/paths_spec.rb +1 -1
  60. data/spec/uploader/processing_spec.rb +11 -0
  61. data/spec/uploader/store_spec.rb +21 -47
  62. data/spec/uploader/versions_spec.rb +0 -8
  63. metadata +105 -17
  64. data/LICENSE +0 -8
  65. data/carrierwave.gemspec +0 -57
  66. data/lib/carrierwave/uploader/default_path.rb +0 -23
  67. data/lib/carrierwave/uploader/paths.rb +0 -27
@@ -21,7 +21,6 @@ require 'spec/autorun'
21
21
  require 'carrierwave'
22
22
 
23
23
  require 'logger'
24
- CarrierWave.logger = Logger.new(nil)
25
24
 
26
25
  alias :running :lambda
27
26
 
@@ -33,8 +32,7 @@ def public_path( *paths )
33
32
  File.expand_path(File.join(File.dirname(__FILE__), 'public', *paths))
34
33
  end
35
34
 
36
- CarrierWave.config[:public] = public_path
37
- CarrierWave.config[:root] = File.expand_path(File.dirname(__FILE__))
35
+ CarrierWave.root = public_path
38
36
 
39
37
  module CarrierWave
40
38
  module Test
@@ -0,0 +1,78 @@
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 = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
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
+ end
47
+
48
+ describe '#retrieve!' do
49
+ before do
50
+ GridFS::GridStore.open(@database, 'uploads/bar.txt', 'w') { |f| f.puts "A test, 1234" }
51
+ @uploader.stub!(:store_path).with('bar.txt').and_return('uploads/bar.txt')
52
+ @grid_fs_file = @storage.retrieve!('bar.txt')
53
+ end
54
+
55
+ it "should retrieve the file contents from gridfs" do
56
+ @grid_fs_file.read.chomp.should == "A test, 1234"
57
+ end
58
+
59
+ it "should not have a path" do
60
+ @grid_fs_file.path.should be_nil
61
+ end
62
+
63
+ it "should not have a URL unless set" do
64
+ @grid_fs_file.url.should be_nil
65
+ end
66
+
67
+ it "should return a URL if configured" do
68
+ @uploader.stub!(:grid_fs_access_url).and_return("/image/show")
69
+ @grid_fs_file.url.should == "/image/show/uploads/bar.txt"
70
+ end
71
+
72
+ it "should be deletable" do
73
+ @grid_fs_file.delete
74
+ GridFS::GridStore.read(@database, 'uploads/bar.txt').should == ''
75
+ end
76
+ end
77
+
78
+ 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,83 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+ require 'aws/s3'
5
+
6
+ if ENV['S3_SPEC']
7
+ describe CarrierWave::Storage::S3 do
8
+ before do
9
+ @uploader = mock('an uploader')
10
+ @uploader.stub!(:s3_access_key_id).and_return(ENV["S3_ACCESS_KEY_ID"])
11
+ @uploader.stub!(:s3_secret_access_key).and_return(ENV["S3_SECRET_ACCESS_KEY"])
12
+ @uploader.stub!(:s3_bucket).and_return(ENV['CARRIERWAVE_TEST_BUCKET'])
13
+ @uploader.stub!(:s3_access).and_return(:public_read)
14
+ @uploader.stub!(:s3_cnamed).and_return(false)
15
+
16
+ @storage = CarrierWave::Storage::S3.new(@uploader)
17
+ @file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
18
+ end
19
+
20
+ after do
21
+ AWS::S3::S3Object.delete('uploads/bar.txt', 'carrierwave_test')
22
+ end
23
+
24
+ describe '#store!' do
25
+ before do
26
+ @uploader.stub!(:store_path).and_return('uploads/bar.txt')
27
+ @s3_file = @storage.store!(@file)
28
+ end
29
+
30
+ it "should upload the file to s3" do
31
+ AWS::S3::S3Object.value('uploads/bar.txt', 'carrierwave_test').should == 'this is stuff'
32
+ end
33
+
34
+ it "should have a path" do
35
+ @s3_file.path.should == 'uploads/bar.txt'
36
+ end
37
+
38
+ it "should have an Amazon URL" do
39
+ @s3_file.url.should == 'http://s3.amazonaws.com/carrierwave_test/uploads/bar.txt'
40
+ end
41
+
42
+ context "with cnamed bucket" do
43
+ it "should have a CNAMED URL" do
44
+ @uploader.stub!(:s3_cnamed).and_return(true)
45
+ @uploader.stub!(:s3_bucket).and_return('foo.bar')
46
+ @s3_file.url.should == 'http://foo.bar/uploads/bar.txt'
47
+ end
48
+ end
49
+
50
+ it "should be deletable" do
51
+ @s3_file.delete
52
+ AWS::S3::S3Object.exists?('uploads/bar.txt', 'carrierwave_test').should be_false
53
+ end
54
+ end
55
+
56
+ describe '#retrieve!' do
57
+ before do
58
+ AWS::S3::S3Object.store('uploads/bar.txt', "A test, 1234", 'carrierwave_test')
59
+
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://s3.amazonaws.com/carrierwave_test/uploads/bar.txt'
74
+ end
75
+
76
+ it "should be deletable" do
77
+ @s3_file.delete
78
+ AWS::S3::S3Object.exists?('uploads/bar.txt', 'carrierwave_test').should be_false
79
+ end
80
+ end
81
+
82
+ end
83
+ end
@@ -51,15 +51,6 @@ describe CarrierWave::Uploader do
51
51
  @uploader.file.exists?.should be_true
52
52
  end
53
53
 
54
- it "should not move it if cache_to_cache_dir is false" do
55
- CarrierWave.config[:cache_to_cache_dir] = false
56
- path = file_path('test.jpg')
57
- @uploader.cache!(File.open(path))
58
- @uploader.current_path.should == path
59
- @uploader.file.exists?.should be_true
60
- CarrierWave.config[:cache_to_cache_dir] = true
61
- end
62
-
63
54
  it "should set the url" do
64
55
  @uploader.cache!(File.open(file_path('test.jpg')))
65
56
  @uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/test.jpg'
@@ -82,13 +73,10 @@ describe CarrierWave::Uploader do
82
73
  end
83
74
 
84
75
  it "should set permissions if options are given" do
85
- old_permissions = CarrierWave.config[:permissions]
86
- CarrierWave.config[:permissions] = 0777
76
+ @uploader_class.permissions = 0777
87
77
 
88
78
  @uploader.cache!(File.open(file_path('test.jpg')))
89
79
  @uploader.should have_permissions(0777)
90
-
91
- CarrierWave.config[:permissions] = old_permissions
92
80
  end
93
81
  end
94
82
 
@@ -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
@@ -13,11 +13,12 @@ describe CarrierWave::Uploader do
13
13
  FileUtils.rm_rf(public_path)
14
14
  end
15
15
 
16
- describe 'with a default path' do
16
+ describe 'with a default url' do
17
17
  before do
18
18
  @uploader_class.class_eval do
19
- def default_path
20
- file_path('test.jpg')
19
+ version :thumb
20
+ def default_url
21
+ ["http://someurl.example.com", version_name].compact.join('/')
21
22
  end
22
23
  end
23
24
  @uploader = @uploader_class.new
@@ -30,8 +31,18 @@ describe CarrierWave::Uploader do
30
31
  end
31
32
 
32
33
  describe '#current_path' do
33
- it "should return the default path" do
34
- @uploader.current_path.should == file_path('test.jpg')
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'
35
46
  end
36
47
  end
37
48
 
@@ -60,6 +71,12 @@ describe CarrierWave::Uploader do
60
71
  @uploader.cache!(File.open(file_path('test.jpg')))
61
72
  @uploader.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/test.jpg')
62
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
63
80
 
64
81
  end
65
82
 
@@ -15,7 +15,7 @@ describe CarrierWave::Uploader do
15
15
 
16
16
  describe '#root' do
17
17
  it "should default to the config option" do
18
- @uploader.root.should == public_path('..')
18
+ @uploader.root.should == public_path
19
19
  end
20
20
  end
21
21