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.

Files changed (92) hide show
  1. data/README.rdoc +33 -15
  2. data/lib/carrierwave.rb +0 -1
  3. data/lib/carrierwave/compatibility/paperclip.rb +2 -2
  4. data/lib/carrierwave/orm/activerecord.rb +9 -5
  5. data/lib/carrierwave/orm/datamapper.rb +10 -0
  6. data/lib/carrierwave/processing/mini_magick.rb +1 -1
  7. data/lib/carrierwave/processing/rmagick.rb +4 -4
  8. data/lib/carrierwave/sanitized_file.rb +2 -2
  9. data/lib/carrierwave/storage/cloud_files.rb +11 -12
  10. data/lib/carrierwave/storage/grid_fs.rb +37 -26
  11. data/lib/carrierwave/storage/right_s3.rb +1 -168
  12. data/lib/carrierwave/storage/s3.rb +73 -66
  13. data/lib/carrierwave/test/matchers.rb +57 -21
  14. data/lib/carrierwave/uploader/configuration.rb +8 -5
  15. data/lib/carrierwave/uploader/processing.rb +1 -0
  16. data/lib/carrierwave/uploader/url.rb +2 -2
  17. data/lib/carrierwave/uploader/versions.rb +10 -0
  18. metadata +31 -279
  19. data/Generators +0 -4
  20. data/History.txt +0 -125
  21. data/Manifest.txt +0 -111
  22. data/Rakefile +0 -39
  23. data/carrierwave.gemspec +0 -85
  24. data/cucumber.yml +0 -2
  25. data/features/caching.feature +0 -28
  26. data/features/download.feature +0 -20
  27. data/features/file_storage.feature +0 -37
  28. data/features/file_storage_overridden_filename.feature +0 -38
  29. data/features/file_storage_overridden_store_dir.feature +0 -38
  30. data/features/file_storage_reversing_processor.feature +0 -43
  31. data/features/fixtures/bork.txt +0 -1
  32. data/features/fixtures/monkey.txt +0 -1
  33. data/features/grid_fs_storage.feature +0 -32
  34. data/features/mount_activerecord.feature +0 -46
  35. data/features/mount_datamapper.feature +0 -46
  36. data/features/step_definitions/activerecord_steps.rb +0 -22
  37. data/features/step_definitions/caching_steps.rb +0 -14
  38. data/features/step_definitions/datamapper_steps.rb +0 -29
  39. data/features/step_definitions/download_steps.rb +0 -4
  40. data/features/step_definitions/file_steps.rb +0 -53
  41. data/features/step_definitions/general_steps.rb +0 -85
  42. data/features/step_definitions/mount_steps.rb +0 -19
  43. data/features/step_definitions/store_steps.rb +0 -18
  44. data/features/support/activerecord.rb +0 -30
  45. data/features/support/datamapper.rb +0 -7
  46. data/features/support/env.rb +0 -22
  47. data/features/versions_basics.feature +0 -50
  48. data/features/versions_nested_versions.feature +0 -70
  49. data/features/versions_overridden_filename.feature +0 -51
  50. data/features/versions_overriden_store_dir.feature +0 -41
  51. data/lib/carrierwave/orm/mongomapper.rb +0 -27
  52. data/merb_generators/uploader_generator.rb +0 -22
  53. data/rails_generators/uploader/USAGE +0 -2
  54. data/rails_generators/uploader/templates/uploader.rb +0 -47
  55. data/rails_generators/uploader/uploader_generator.rb +0 -21
  56. data/script/console +0 -10
  57. data/script/destroy +0 -14
  58. data/script/generate +0 -14
  59. data/spec/compatibility/paperclip_spec.rb +0 -52
  60. data/spec/fixtures/bork.txt +0 -1
  61. data/spec/fixtures/landscape.jpg +0 -0
  62. data/spec/fixtures/portrait.jpg +0 -0
  63. data/spec/fixtures/test.jpeg +0 -1
  64. data/spec/fixtures/test.jpg +0 -1
  65. data/spec/mount_spec.rb +0 -538
  66. data/spec/orm/activerecord_spec.rb +0 -271
  67. data/spec/orm/datamapper_spec.rb +0 -168
  68. data/spec/orm/mongoid_spec.rb +0 -202
  69. data/spec/orm/mongomapper_spec.rb +0 -202
  70. data/spec/orm/sequel_spec.rb +0 -183
  71. data/spec/processing/image_science_spec.rb +0 -56
  72. data/spec/processing/mini_magick_spec.rb +0 -76
  73. data/spec/processing/rmagick_spec.rb +0 -75
  74. data/spec/sanitized_file_spec.rb +0 -623
  75. data/spec/spec_helper.rb +0 -92
  76. data/spec/storage/cloudfiles_spec.rb +0 -78
  77. data/spec/storage/grid_fs_spec.rb +0 -83
  78. data/spec/storage/right_s3_spec.rb +0 -83
  79. data/spec/storage/s3_spec.rb +0 -95
  80. data/spec/uploader/cache_spec.rb +0 -209
  81. data/spec/uploader/configuration_spec.rb +0 -105
  82. data/spec/uploader/default_url_spec.rb +0 -85
  83. data/spec/uploader/download_spec.rb +0 -75
  84. data/spec/uploader/extension_whitelist_spec.rb +0 -44
  85. data/spec/uploader/mountable_spec.rb +0 -33
  86. data/spec/uploader/paths_spec.rb +0 -22
  87. data/spec/uploader/processing_spec.rb +0 -73
  88. data/spec/uploader/proxy_spec.rb +0 -54
  89. data/spec/uploader/remove_spec.rb +0 -70
  90. data/spec/uploader/store_spec.rb +0 -264
  91. data/spec/uploader/url_spec.rb +0 -102
  92. data/spec/uploader/versions_spec.rb +0 -298
@@ -1,271 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- require 'carrierwave/orm/activerecord'
6
-
7
- # change this if sqlite is unavailable
8
- dbconfig = {
9
- :adapter => 'sqlite3',
10
- :database => ':memory:'
11
- }
12
-
13
- ActiveRecord::Base.establish_connection(dbconfig)
14
- ActiveRecord::Migration.verbose = false
15
-
16
- class TestMigration < ActiveRecord::Migration
17
- def self.up
18
- create_table :events, :force => true do |t|
19
- t.column :image, :string
20
- t.column :textfile, :string
21
- t.column :foo, :string
22
- end
23
- end
24
-
25
- def self.down
26
- drop_table :events
27
- end
28
- end
29
-
30
- class Event < ActiveRecord::Base; end # setup a basic AR class for testing
31
- $arclass = 0
32
-
33
- describe CarrierWave::ActiveRecord do
34
-
35
- describe '.mount_uploader' do
36
-
37
- before(:all) { TestMigration.up }
38
- after(:all) { TestMigration.down }
39
- after { Event.delete_all }
40
-
41
- before do
42
- # My god, what a horrible, horrible solution, but AR validations don't work
43
- # unless the class has a name. This is the best I could come up with :S
44
- $arclass += 1
45
- eval <<-RUBY
46
- class Event#{$arclass} < Event; end
47
- @class = Event#{$arclass}
48
- RUBY
49
- @class.table_name = "events"
50
- @uploader = Class.new(CarrierWave::Uploader::Base)
51
- @class.mount_uploader(:image, @uploader)
52
- @event = @class.new
53
- end
54
-
55
- describe '#image' do
56
-
57
- it "should return blank uploader when nothing has been assigned" do
58
- @event.image.should be_blank
59
- end
60
-
61
- it "should return blank uploader when an empty string has been assigned" do
62
- @event[:image] = ''
63
- @event.save
64
- @event.reload
65
- @event.image.should be_blank
66
- end
67
-
68
- it "should retrieve a file from the storage if a value is stored in the database" do
69
- @event[:image] = 'test.jpeg'
70
- @event.save
71
- @event.reload
72
- @event.image.should be_an_instance_of(@uploader)
73
- end
74
-
75
- it "should set the path to the store dir" do
76
- @event[:image] = 'test.jpeg'
77
- @event.save
78
- @event.reload
79
- @event.image.current_path.should == public_path('uploads/test.jpeg')
80
- end
81
-
82
- end
83
-
84
- describe '#image=' do
85
-
86
- it "should cache a file" do
87
- @event.image = stub_file('test.jpeg')
88
- @event.image.should be_an_instance_of(@uploader)
89
- end
90
-
91
- it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
92
- @event[:image].should be_nil
93
- end
94
-
95
- it "should copy a file into into the cache directory" do
96
- @event.image = stub_file('test.jpeg')
97
- @event.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
98
- end
99
-
100
- it "should do nothing when nil is assigned" do
101
- @event.image = nil
102
- @event.image.should be_blank
103
- end
104
-
105
- it "should do nothing when an empty string is assigned" do
106
- @event.image = ''
107
- @event.image.should be_blank
108
- end
109
-
110
- it "should make the record invalid when an integrity error occurs" do
111
- @uploader.class_eval do
112
- def extension_white_list
113
- %(txt)
114
- end
115
- end
116
- @event.image = stub_file('test.jpg')
117
- @event.should_not be_valid
118
- end
119
-
120
- it "should make the record invalid when a processing error occurs" do
121
- @uploader.class_eval do
122
- process :monkey
123
- def monkey
124
- raise CarrierWave::ProcessingError, "Ohh noez!"
125
- end
126
- end
127
- @event.image = stub_file('test.jpg')
128
- @event.should_not be_valid
129
- end
130
-
131
- end
132
-
133
- describe '#save' do
134
-
135
- it "should do nothing when no file has been assigned" do
136
- @event.save.should be_true
137
- @event.image.should be_blank
138
- end
139
-
140
- it "should copy the file to the upload directory when a file has been assigned" do
141
- @event.image = stub_file('test.jpeg')
142
- @event.save.should be_true
143
- @event.image.should be_an_instance_of(@uploader)
144
- @event.image.current_path.should == public_path('uploads/test.jpeg')
145
- end
146
-
147
- it "should do nothing when a validation fails" do
148
- @class.validate { |r| r.errors.add :textfile, "FAIL!" }
149
- @event.image = stub_file('test.jpeg')
150
- @event.save.should be_false
151
- @event.image.should be_an_instance_of(@uploader)
152
- @event.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
153
- end
154
-
155
- it "should assign the filename to the database" do
156
- @event.image = stub_file('test.jpeg')
157
- @event.save.should be_true
158
- @event.reload
159
- @event[:image].should == 'test.jpeg'
160
- end
161
-
162
- it "should preserve the image when nothing is assigned" do
163
- @event.image = stub_file('test.jpeg')
164
- @event.save.should be_true
165
- @event = @class.find(@event.id)
166
- @event.foo = "bar"
167
- @event.save.should be_true
168
- @event[:image].should == 'test.jpeg'
169
- end
170
-
171
- it "should remove the image if remove_image? returns true" do
172
- @event.image = stub_file('test.jpeg')
173
- @event.save!
174
- @event.remove_image = true
175
- @event.save!
176
- @event.reload
177
- @event.image.should be_blank
178
- @event[:image].should == ''
179
- end
180
-
181
- end
182
-
183
- describe '#destroy' do
184
-
185
- it "should do nothing when no file has been assigned" do
186
- @event.save.should be_true
187
- @event.destroy
188
- end
189
-
190
- it "should remove the file from the filesystem" do
191
- @event.image = stub_file('test.jpeg')
192
- @event.save.should be_true
193
- @event.image.should be_an_instance_of(@uploader)
194
- @event.image.current_path.should == public_path('uploads/test.jpeg')
195
- @event.destroy
196
- File.exist?(public_path('uploads/test.jpeg')).should be_false
197
- end
198
-
199
- end
200
-
201
- describe 'with overriddent filename' do
202
-
203
- describe '#save' do
204
-
205
- before do
206
- @uploader.class_eval do
207
- def filename
208
- model.name + File.extname(super)
209
- end
210
- end
211
- @event.stub!(:name).and_return('jonas')
212
- end
213
-
214
- it "should copy the file to the upload directory when a file has been assigned" do
215
- @event.image = stub_file('test.jpeg')
216
- @event.save.should be_true
217
- @event.image.should be_an_instance_of(@uploader)
218
- @event.image.current_path.should == public_path('uploads/jonas.jpeg')
219
- end
220
-
221
- it "should assign an overridden filename to the database" do
222
- @event.image = stub_file('test.jpeg')
223
- @event.save.should be_true
224
- @event.reload
225
- @event[:image].should == 'jonas.jpeg'
226
- end
227
-
228
- end
229
-
230
- end
231
-
232
- describe 'with validates_presence_of' do
233
-
234
- before do
235
- @class.validates_presence_of :image
236
- @event.stub!(:name).and_return('jonas')
237
- end
238
-
239
- it "should be valid if a file has been cached" do
240
- @event.image = stub_file('test.jpeg')
241
- @event.should be_valid
242
- end
243
-
244
- it "should not be valid if a file has not been cached" do
245
- @event.should_not be_valid
246
- end
247
-
248
- end
249
-
250
- describe 'with validates_size_of' do
251
-
252
- before do
253
- @class.validates_size_of :image, :maximum => 40
254
- @event.stub!(:name).and_return('jonas')
255
- end
256
-
257
- it "should be valid if a file has been cached that matches the size criteria" do
258
- @event.image = stub_file('test.jpeg')
259
- @event.should be_valid
260
- end
261
-
262
- it "should not be valid if a file has been cached that does not match the size criteria" do
263
- @event.image = stub_file('bork.txt')
264
- @event.should_not be_valid
265
- end
266
-
267
- end
268
-
269
- end
270
-
271
- end
@@ -1,168 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- require 'dm-core'
6
- require 'dm-validations'
7
- require 'carrierwave/orm/datamapper'
8
-
9
- DataMapper.setup(:default, 'sqlite3::memory:')
10
-
11
- describe CarrierWave::DataMapper do
12
-
13
- before do
14
- uploader = Class.new(CarrierWave::Uploader::Base)
15
-
16
- @class = Class.new
17
- @class.class_eval do
18
- include DataMapper::Resource
19
-
20
- storage_names[:default] = 'events'
21
-
22
- property :id, DataMapper::Types::Serial
23
-
24
- # auto validation off currently for inferred type
25
- # validation. issue is that validations are done on
26
- # the value returned by model#property_name which is overloaded
27
- # by carrierwave. pull request in @dm-more to remedy this.
28
- property :image, String, :auto_validation => false
29
-
30
- mount_uploader :image, uploader
31
- end
32
-
33
- @class.auto_migrate!
34
-
35
- @uploader = uploader
36
-
37
- @event = @class.new
38
- end
39
-
40
- describe '#image' do
41
-
42
- it "should return blank uploader when nothing has been assigned" do
43
- @event.image.should be_blank
44
- end
45
-
46
- it "should return blank uploader when an empty string has been assigned" do
47
- repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('')")
48
- @event = @class.first
49
-
50
- @event.image.should be_blank
51
- end
52
-
53
- it "should retrieve a file from the storage if a value is stored in the database" do
54
- repository(:default).adapter.execute("INSERT INTO events (image) VALUES ('test.jpg')")
55
- @event = @class.first
56
-
57
- @event.save
58
- @event.reload
59
- @event.image.should be_an_instance_of(@uploader)
60
- end
61
-
62
- it "should set the path to the store dir" do
63
- @event.attribute_set(:image, 'test.jpeg')
64
- @event.save
65
- @event.reload
66
- @event.image.current_path.should == public_path('uploads/test.jpeg')
67
- end
68
-
69
- end
70
-
71
- describe '#image=' do
72
-
73
- it "should cache a file" do
74
- @event.image = stub_file('test.jpeg')
75
- @event.image.should be_an_instance_of(@uploader)
76
- end
77
-
78
- it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
79
- @event.attribute_get(:image).should be_nil
80
- end
81
-
82
- it "should copy a file into into the cache directory" do
83
- @event.image = stub_file('test.jpeg')
84
- @event.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
85
- end
86
-
87
- it "should do nothing when nil is assigned" do
88
- @event.image = nil
89
- @event.image.should be_blank
90
- end
91
-
92
- it "should do nothing when an empty string is assigned" do
93
- @event.image = ''
94
- @event.image.should be_blank
95
- end
96
-
97
- end
98
-
99
- describe '#save' do
100
-
101
- it "should do nothing when no file has been assigned" do
102
- @event.save
103
- @event.image.should be_blank
104
- end
105
-
106
- it "should copy the file to the upload directory when a file has been assigned" do
107
- @event.image = stub_file('test.jpeg')
108
- @event.save
109
- @event.image.should be_an_instance_of(@uploader)
110
- @event.image.current_path.should == public_path('uploads/test.jpeg')
111
- end
112
-
113
- it "should assign the filename to the database" do
114
- @event.image = stub_file('test.jpeg')
115
- @event.save
116
- @event.reload
117
- @event.attribute_get(:image).should == 'test.jpeg'
118
- end
119
-
120
- it "should remove the image if remove_image? returns true" do
121
- @event.image = stub_file('test.jpeg')
122
- @event.save
123
- @event.remove_image = true
124
- @event.save
125
- @event.reload
126
- @event.image.should be_blank
127
- @event.attribute_get(:image).should == ''
128
- end
129
-
130
- describe "with validations" do
131
- it "should do nothing when a validation fails" do
132
- @class.validates_with_block(:textfile) { [false, "FAIL!"] }
133
- @event.image = stub_file('test.jpeg')
134
- @event.save
135
- @event.image.should be_an_instance_of(@uploader)
136
- @event.image.current_path.should =~ /^#{public_path('uploads/tmp')}/
137
- end
138
-
139
- it "should assign the filename before validation" do
140
- @class.validates_with_block(:image) { [false, "FAIL!"] if self.image.nil? }
141
- @event.image = stub_file('test.jpeg')
142
- @event.save
143
- @event.reload
144
- @event.attribute_get(:image).should == 'test.jpeg'
145
- end
146
- end
147
-
148
- end
149
-
150
- describe '#destroy' do
151
-
152
- it "should do nothing when no file has been assigned" do
153
- @event.destroy
154
- end
155
-
156
- it "should remove the file from the filesystem" do
157
- @event.image = stub_file('test.jpeg')
158
- @event.save.should be_true
159
- File.exist?(public_path('uploads/test.jpeg')).should be_true
160
- @event.image.should be_an_instance_of(@uploader)
161
- @event.image.current_path.should == public_path('uploads/test.jpeg')
162
- @event.destroy
163
- File.exist?(public_path('uploads/test.jpeg')).should be_false
164
- end
165
-
166
- end
167
-
168
- end
@@ -1,202 +0,0 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
3
-
4
- require 'carrierwave/orm/mongoid'
5
-
6
- connection = Mongo::Connection.new
7
- Mongoid.database = connection.db("carrierwave_test")
8
-
9
- MongoidUploader = Class.new(CarrierWave::Uploader::Base)
10
- MongoidUser = Class.new
11
- MongoidUser.class_eval do
12
- include Mongoid::Document
13
- store_in :users
14
- mount_uploader :image, MongoidUploader
15
- end
16
-
17
- describe CarrierWave::Mongoid do
18
-
19
- after do
20
- MongoidUser.collection.drop
21
- end
22
-
23
- describe '#image' do
24
-
25
- context "when nothing is assigned" do
26
-
27
- before do
28
- @document = MongoidUser.new
29
- end
30
-
31
- it "returns a blank uploader" do
32
- @document.image.should be_blank
33
- end
34
-
35
- end
36
-
37
- context "when an empty string is assigned" do
38
-
39
- before do
40
- @document = MongoidUser.new(:image_filename => "")
41
- @document.save
42
- end
43
-
44
- it "returns a blank uploader" do
45
- @saved_doc = MongoidUser.first
46
- @saved_doc.image.should be_blank
47
- end
48
-
49
- end
50
-
51
- context "when a filename is saved in the database" do
52
-
53
- before do
54
- @document = MongoidUser.new(:image_filename => "test.jpg")
55
- @document.save
56
- @doc = MongoidUser.first
57
- end
58
-
59
- it "returns an uploader" do
60
- @doc.image.should be_an_instance_of(MongoidUploader)
61
- end
62
-
63
- it "sets the path to the store directory" do
64
- @doc.image.current_path.should == public_path('uploads/test.jpg')
65
- end
66
-
67
- end
68
-
69
- end
70
-
71
- describe '#image=' do
72
-
73
- before do
74
- @doc = MongoidUser.new
75
- end
76
-
77
- context "when nil is assigned" do
78
-
79
- it "does not set the value" do
80
- @doc.image = nil
81
- @doc.image.should be_blank
82
- end
83
-
84
- end
85
-
86
- context "when an empty string is assigned" do
87
-
88
- it "does not set the value" do
89
- @doc.image = ''
90
- @doc.image.should be_blank
91
- end
92
-
93
- end
94
-
95
- context "when a file is assigned" do
96
-
97
- it "should cache a file" do
98
- @doc.image = stub_file('test.jpeg')
99
- @doc.image.should be_an_instance_of(MongoidUploader)
100
- end
101
-
102
- it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
103
- @doc.image_filename.should be_nil
104
- end
105
-
106
- it "should copy a file into into the cache directory" do
107
- @doc.image = stub_file('test.jpeg')
108
- @doc.image.current_path.should =~ /^#{public_path('uploads\/tmp')}/
109
- end
110
-
111
- end
112
-
113
- end
114
-
115
- describe "#save" do
116
-
117
- before do
118
- @doc = MongoidUser.new
119
- end
120
-
121
- context "when no file is assigned" do
122
-
123
- it "image is blank" do
124
- @doc.save
125
- @doc.image.should be_blank
126
- end
127
-
128
- end
129
-
130
- context "when a file is assigned" do
131
-
132
- it "copies the file to the upload directory" do
133
- @doc.image = stub_file('test.jpg')
134
- @doc.save
135
- @doc.image.should be_an_instance_of(MongoidUploader)
136
- @doc.image.current_path.should == public_path('uploads/test.jpg')
137
- end
138
-
139
- it "saves the filename in the database" do
140
- @doc.image = stub_file('test.jpg')
141
- @doc.save
142
- @doc.image_filename.should == 'test.jpg'
143
- end
144
-
145
- context "when remove_image? is true" do
146
-
147
- it "removes the image" do
148
- @doc.image = stub_file('test.jpeg')
149
- @doc.save
150
- @doc.remove_image = true
151
- @doc.save
152
- @doc.image.should be_blank
153
- @doc.image_filename.should == ''
154
- end
155
-
156
- end
157
-
158
- end
159
-
160
- end
161
-
162
- describe '#destroy' do
163
-
164
- before do
165
- @doc = MongoidUser.new
166
- end
167
-
168
- describe "when file assigned" do
169
-
170
- it "removes the file from the filesystem" do
171
- @doc.image = stub_file('test.jpeg')
172
- @doc.save.should be_true
173
- File.exist?(public_path('uploads/test.jpeg')).should be_true
174
- @doc.image.should be_an_instance_of(MongoidUploader)
175
- @doc.image.current_path.should == public_path('uploads/test.jpeg')
176
- @doc.destroy
177
- File.exist?(public_path('uploads/test.jpeg')).should be_false
178
- end
179
-
180
- end
181
-
182
- describe "when file is not assigned" do
183
-
184
- it "deletes the instance of MongoidUser after save" do
185
- @doc.save
186
- MongoidUser.count.should eql(1)
187
- @doc.destroy
188
- end
189
-
190
- it "deletes the instance of MongoidUser after save and then re-looking up the instance" do
191
- @doc.save
192
- MongoidUser.count.should eql(1)
193
- @doc = MongoidUser.first
194
- @doc.destroy
195
- end
196
-
197
- end
198
-
199
- end
200
-
201
-
202
- end