carrierwave-mongoid 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +5 -2
- data/Rakefile +5 -8
- data/carrierwave-mongoid.gemspec +3 -3
- data/gemfiles/carrierwave-0.10.gemfile +5 -0
- data/lib/carrierwave/mongoid/version.rb +1 -1
- data/spec/mongoid_spec.rb +164 -166
- data/spec/spec_helper.rb +9 -5
- data/spec/storage/grid_fs_spec.rb +29 -38
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3be7d8b5af73afbd1afcc8997af9c51d1fb64a8a
|
4
|
+
data.tar.gz: 10fbaae7408d800ec49a7a1ab7e15e05b1a8a61c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9020c5a0e04cda97110fc1b1f44135cff2e8a778de6635f46ac731880334184b61bb8d827b21c116d8154959abfc3af7ef8767b82a10ca3d3b56ae5dbaa07149
|
7
|
+
data.tar.gz: b60d1b0b3af9f8903b4e72509954e8cb31a03bb4862a6faf2fb8166a710f38cb3166570dc0d79eb381230fe2ef0cb5be9d1caff603fa0b214f4f4c132583f3c4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# CarrierWave for Mongoid
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/carrierwave-mongoid)
|
4
|
+
[](http://travis-ci.org/carrierwaveuploader/carrierwave-mongoid)
|
5
|
+
[](https://codeclimate.com/github/carrierwaveuploader/carrierwave-mongoid)
|
6
|
+
[](https://rubygems.org/gems/carrierwave-mongoid)
|
7
|
+
|
3
8
|
This gem adds support for Mongoid and MongoDB's GridFS to
|
4
9
|
[CarrierWave](https://github.com/carrierwaveuploader/carrierwave/)
|
5
10
|
|
6
11
|
This functionality used to be part of CarrierWave but has since been extracted
|
7
12
|
into this gem.
|
8
13
|
|
9
|
-
[](https://rubygems.org/gems/carrierwave-mongoid) [](http://travis-ci.org/carrierwaveuploader/carrierwave-mongoid) [](https://codeclimate.com/github/carrierwaveuploader/carrierwave-mongoid)
|
10
|
-
|
11
14
|
## Installation
|
12
15
|
|
13
16
|
Install the latest release:
|
data/Rakefile
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require
|
2
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
require "bundler/gem_tasks"
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#t.rspec_path = 'bin/rspec'
|
9
|
-
t.rspec_opts = %w[--color]
|
3
|
+
begin
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
rescue LoadError
|
10
7
|
end
|
11
8
|
|
12
9
|
task :default => :spec
|
data/carrierwave-mongoid.gemspec
CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
s.add_dependency "carrierwave", [">= 0.8.0", "< 0.
|
23
|
+
s.add_dependency "carrierwave", [">= 0.8.0", "< 0.12.0"]
|
24
24
|
s.add_dependency "mongoid", [">= 3.0", "< 6.0"]
|
25
25
|
s.add_dependency "mongoid-grid_fs", [">= 1.3", "< 3.0"]
|
26
|
-
s.add_development_dependency "rspec",
|
27
|
-
s.add_development_dependency "rake",
|
26
|
+
s.add_development_dependency "rspec", "~>3.4.0"
|
27
|
+
s.add_development_dependency "rake", "~>11.1.2"
|
28
28
|
s.add_development_dependency "mini_magick"
|
29
29
|
s.add_development_dependency "pry"
|
30
30
|
end
|
data/spec/mongoid_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
require 'carrierwave/mongoid'
|
5
|
-
|
6
4
|
def reset_mongo_class(uploader = MongoUploader)
|
7
5
|
define_mongo_class('MongoUser') do
|
8
6
|
include Mongoid::Document
|
@@ -59,7 +57,7 @@ describe CarrierWave::Mongoid do
|
|
59
57
|
end
|
60
58
|
|
61
59
|
it "returns a blank uploader" do
|
62
|
-
@document.image.
|
60
|
+
expect(@document.image).to be_blank
|
63
61
|
end
|
64
62
|
|
65
63
|
end
|
@@ -74,7 +72,7 @@ describe CarrierWave::Mongoid do
|
|
74
72
|
|
75
73
|
it "returns a blank uploader" do
|
76
74
|
@saved_doc = MongoUser.first
|
77
|
-
@saved_doc.image.
|
75
|
+
expect(@saved_doc.image).to be_blank
|
78
76
|
end
|
79
77
|
|
80
78
|
end
|
@@ -91,19 +89,19 @@ describe CarrierWave::Mongoid do
|
|
91
89
|
end
|
92
90
|
|
93
91
|
it "returns an uploader" do
|
94
|
-
@doc.image.
|
92
|
+
expect(@doc.image).to be_an_instance_of(MongoUploader)
|
95
93
|
end
|
96
94
|
|
97
95
|
it "sets the path to the store directory" do
|
98
|
-
@doc.image.current_path.
|
96
|
+
expect(@doc.image.current_path).to eq public_path('uploads/test.jpg')
|
99
97
|
end
|
100
98
|
|
101
99
|
it "should return valid JSON when to_json is called when image is nil" do
|
102
100
|
@doc[:image] = nil
|
103
101
|
hash = JSON.parse(@doc.to_json)
|
104
|
-
hash.keys.
|
105
|
-
hash["image"].keys.
|
106
|
-
hash["image"]["url"].
|
102
|
+
expect(hash.keys).to include("image")
|
103
|
+
expect(hash["image"].keys).to include("url")
|
104
|
+
expect(hash["image"]["url"]).to be_nil
|
107
105
|
end
|
108
106
|
|
109
107
|
it "should return valid JSON when to_json is called when image is present" do
|
@@ -111,7 +109,7 @@ describe CarrierWave::Mongoid do
|
|
111
109
|
@doc.save!
|
112
110
|
@doc.reload
|
113
111
|
|
114
|
-
JSON.parse(@doc.to_json)["image"].
|
112
|
+
expect(JSON.parse(@doc.to_json)["image"]).to eq("url" => "/uploads/test.jpeg")
|
115
113
|
end
|
116
114
|
|
117
115
|
it "should return valid JSON when to_json is called on a collection containing uploader from a model" do
|
@@ -119,14 +117,14 @@ describe CarrierWave::Mongoid do
|
|
119
117
|
@doc.save!
|
120
118
|
@doc.reload
|
121
119
|
|
122
|
-
JSON.parse({:data => @doc.image}.to_json).
|
120
|
+
expect(JSON.parse({:data => @doc.image}.to_json)).to eq("data"=>{"image"=>{"url"=>"/uploads/test.jpeg"}})
|
123
121
|
end
|
124
122
|
|
125
123
|
it "should respect options[:only] when passed to to_json for the serializable hash" do
|
126
124
|
@doc[:image] = 'test.jpeg'
|
127
125
|
@doc.save!
|
128
126
|
@doc.reload
|
129
|
-
JSON.parse(@doc.to_json({:only => [:_id]})).
|
127
|
+
expect(JSON.parse(@doc.to_json({:only => [:_id]}))).to eq("_id" => @doc.id.as_json)
|
130
128
|
end
|
131
129
|
|
132
130
|
it "should respect options[:except] when passed to to_json for the serializable hash" do
|
@@ -134,7 +132,7 @@ describe CarrierWave::Mongoid do
|
|
134
132
|
@doc.save!
|
135
133
|
@doc.reload
|
136
134
|
|
137
|
-
JSON.parse(@doc.to_json({:except => [:_id, :image]})).
|
135
|
+
expect(JSON.parse(@doc.to_json({:except => [:_id, :image]}))).to eq("folder" => "")
|
138
136
|
end
|
139
137
|
|
140
138
|
end
|
@@ -152,7 +150,7 @@ describe CarrierWave::Mongoid do
|
|
152
150
|
|
153
151
|
it "does not set the value" do
|
154
152
|
@doc.image = nil
|
155
|
-
@doc.image.
|
153
|
+
expect(@doc.image).to be_blank
|
156
154
|
end
|
157
155
|
|
158
156
|
end
|
@@ -161,7 +159,7 @@ describe CarrierWave::Mongoid do
|
|
161
159
|
|
162
160
|
it "does not set the value" do
|
163
161
|
@doc.image = ''
|
164
|
-
@doc.image.
|
162
|
+
expect(@doc.image).to be_blank
|
165
163
|
end
|
166
164
|
|
167
165
|
end
|
@@ -170,16 +168,16 @@ describe CarrierWave::Mongoid do
|
|
170
168
|
|
171
169
|
it "should cache a file" do
|
172
170
|
@doc.image = stub_file('test.jpeg')
|
173
|
-
@doc.image.
|
171
|
+
expect(@doc.image).to be_an_instance_of(MongoUploader)
|
174
172
|
end
|
175
173
|
|
176
174
|
it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
|
177
|
-
@doc[:image].
|
175
|
+
expect(@doc[:image]).to be_nil
|
178
176
|
end
|
179
177
|
|
180
178
|
it "should copy a file into into the cache directory" do
|
181
179
|
@doc.image = stub_file('test.jpeg')
|
182
|
-
@doc.image.current_path.
|
180
|
+
expect(@doc.image.current_path).to match /^#{public_path('uploads\/tmp')}/
|
183
181
|
end
|
184
182
|
|
185
183
|
end
|
@@ -192,20 +190,20 @@ describe CarrierWave::Mongoid do
|
|
192
190
|
end
|
193
191
|
|
194
192
|
it "should make the document invalid when an integrity error occurs" do
|
195
|
-
@doc.
|
193
|
+
expect(@doc).to_not be_valid
|
196
194
|
end
|
197
195
|
|
198
196
|
it "should use I18n for integrity error messages" do
|
199
197
|
translations = { mongoid: { errors: { messages: { carrierwave_integrity_error: 'is not of an allowed file type' }}}}
|
200
198
|
change_locale_and_store_translations(:en, translations) do
|
201
199
|
@doc.valid?
|
202
|
-
@doc.errors[:image].
|
200
|
+
expect(@doc.errors[:image]).to eq ['is not of an allowed file type']
|
203
201
|
end
|
204
202
|
|
205
203
|
translations = { mongoid: { errors: { messages: { carrierwave_integrity_error: 'tipo de imagem não permitido.' }}}}
|
206
204
|
change_locale_and_store_translations(:pt, translations) do
|
207
205
|
@doc.valid?
|
208
|
-
@doc.errors[:image].
|
206
|
+
expect(@doc.errors[:image]).to eq ['tipo de imagem não permitido.']
|
209
207
|
end
|
210
208
|
end
|
211
209
|
end
|
@@ -218,20 +216,20 @@ describe CarrierWave::Mongoid do
|
|
218
216
|
end
|
219
217
|
|
220
218
|
it "should make the document invalid when a processing error occurs" do
|
221
|
-
@doc.
|
219
|
+
expect(@doc).to_not be_valid
|
222
220
|
end
|
223
221
|
|
224
222
|
it "should use I18n for processing error messages" do
|
225
223
|
translations = { mongoid: { errors: { messages: { carrierwave_processing_error: 'failed to be processed' }}}}
|
226
224
|
change_locale_and_store_translations(:en, translations) do
|
227
225
|
@doc.valid?
|
228
|
-
@doc.errors[:image].
|
226
|
+
expect(@doc.errors[:image]).to eq ['failed to be processed']
|
229
227
|
end
|
230
228
|
|
231
229
|
translations = { mongoid: { errors: { messages: { carrierwave_processing_error: 'falha ao processar imagem.' }}}}
|
232
230
|
change_locale_and_store_translations(:pt, translations) do
|
233
231
|
@doc.valid?
|
234
|
-
@doc.errors[:image].
|
232
|
+
expect(@doc.errors[:image]).to eq ['falha ao processar imagem.']
|
235
233
|
end
|
236
234
|
end
|
237
235
|
end
|
@@ -246,27 +244,27 @@ describe CarrierWave::Mongoid do
|
|
246
244
|
|
247
245
|
it "treats true argument such that attribute is marked as changed" do
|
248
246
|
@doc.remove_image = true
|
249
|
-
@doc.
|
247
|
+
expect(@doc).to be_image_changed
|
250
248
|
end
|
251
249
|
|
252
250
|
it "treats '1' argument such that attribute is marked as changed" do
|
253
251
|
@doc.remove_image = '1'
|
254
|
-
@doc.
|
252
|
+
expect(@doc).to be_image_changed
|
255
253
|
end
|
256
254
|
|
257
255
|
it "treats false argument such that attribute is not marked as changed" do
|
258
256
|
@doc.remove_image = false
|
259
|
-
@doc.
|
257
|
+
expect(@doc).to_not be_image_changed
|
260
258
|
end
|
261
259
|
|
262
260
|
it "treats nil argument such that attribute is not marked as changed" do
|
263
261
|
@doc.remove_image = nil
|
264
|
-
@doc.
|
262
|
+
expect(@doc).to_not be_image_changed
|
265
263
|
end
|
266
264
|
|
267
265
|
it "treats '0' argument such that attribute is not marked as changed" do
|
268
266
|
@doc.remove_image = '0'
|
269
|
-
@doc.
|
267
|
+
expect(@doc).to_not be_image_changed
|
270
268
|
end
|
271
269
|
end
|
272
270
|
|
@@ -274,9 +272,9 @@ describe CarrierWave::Mongoid do
|
|
274
272
|
|
275
273
|
it "after it was initialized with params" do
|
276
274
|
doc = reset_mongo_class.new(:image => stub_file('test.jpg'))
|
277
|
-
doc.save.
|
278
|
-
doc.image.
|
279
|
-
doc.image.current_path.
|
275
|
+
expect(doc.save).to be_truthy
|
276
|
+
expect(doc.image).to be_an_instance_of(MongoUploader)
|
277
|
+
expect(doc.image.current_path).to eq public_path('uploads/test.jpg')
|
280
278
|
end
|
281
279
|
|
282
280
|
before do
|
@@ -287,8 +285,8 @@ describe CarrierWave::Mongoid do
|
|
287
285
|
context "when no file is assigned" do
|
288
286
|
|
289
287
|
it "image is blank" do
|
290
|
-
@doc.save.
|
291
|
-
@doc.image.
|
288
|
+
expect(@doc.save).to be_truthy
|
289
|
+
expect(@doc.image).to be_blank
|
292
290
|
end
|
293
291
|
|
294
292
|
end
|
@@ -297,16 +295,16 @@ describe CarrierWave::Mongoid do
|
|
297
295
|
|
298
296
|
it "copies the file to the upload directory" do
|
299
297
|
@doc.image = stub_file('test.jpg')
|
300
|
-
@doc.save.
|
301
|
-
@doc.image.
|
302
|
-
@doc.image.current_path.
|
298
|
+
expect(@doc.save).to be_truthy
|
299
|
+
expect(@doc.image).to be_an_instance_of(MongoUploader)
|
300
|
+
expect(@doc.image.current_path).to eq public_path('uploads/test.jpg')
|
303
301
|
end
|
304
302
|
|
305
303
|
it "saves the filename in the database" do
|
306
304
|
@doc.image = stub_file('test.jpg')
|
307
|
-
@doc.save.
|
308
|
-
@doc[:image].
|
309
|
-
@doc.image_identifier.
|
305
|
+
expect(@doc.save).to be_truthy
|
306
|
+
expect(@doc[:image]).to eq 'test.jpg'
|
307
|
+
expect(@doc.image_identifier).to eq 'test.jpg'
|
310
308
|
end
|
311
309
|
|
312
310
|
context "when remove_image? is true" do
|
@@ -315,23 +313,23 @@ describe CarrierWave::Mongoid do
|
|
315
313
|
@doc.image = stub_file('test.jpeg')
|
316
314
|
@doc.save
|
317
315
|
@doc.remove_image = true
|
318
|
-
@doc.save.
|
316
|
+
expect(@doc.save).to be_truthy
|
319
317
|
@doc.reload
|
320
|
-
@doc.image.
|
321
|
-
@doc.image_identifier.
|
318
|
+
expect(@doc.image).to be_blank
|
319
|
+
expect(@doc.image_identifier).to be_blank
|
322
320
|
end
|
323
321
|
|
324
322
|
end
|
325
323
|
|
326
324
|
it "should mark image as changed when saving a new image" do
|
327
|
-
@doc.image_changed
|
325
|
+
expect(@doc.image_changed?).to be_falsey
|
328
326
|
@doc.image = stub_file("test.jpeg")
|
329
|
-
@doc.image_changed
|
327
|
+
expect(@doc.image_changed?).to be_truthy
|
330
328
|
@doc.save
|
331
329
|
@doc.reload
|
332
|
-
@doc.image_changed
|
330
|
+
expect(@doc.image_changed?).to be_falsey
|
333
331
|
@doc.image = stub_file("test.jpg")
|
334
|
-
@doc.image_changed
|
332
|
+
expect(@doc.image_changed?).to be_truthy
|
335
333
|
end
|
336
334
|
|
337
335
|
end
|
@@ -352,8 +350,8 @@ describe CarrierWave::Mongoid do
|
|
352
350
|
@doc.image = stub_file('test.jpeg')
|
353
351
|
@doc.save
|
354
352
|
@doc.reload
|
355
|
-
@doc[:image].
|
356
|
-
@doc.image_identifier.
|
353
|
+
expect(@doc[:image]).to eq 'test.jpeg'
|
354
|
+
expect(@doc.image_identifier).to eq 'test.jpeg'
|
357
355
|
end
|
358
356
|
|
359
357
|
end
|
@@ -369,12 +367,12 @@ describe CarrierWave::Mongoid do
|
|
369
367
|
|
370
368
|
it "removes the file from the filesystem" do
|
371
369
|
@doc.image = stub_file('test.jpeg')
|
372
|
-
@doc.save.
|
373
|
-
File.exist?(public_path('uploads/test.jpeg')).
|
374
|
-
@doc.image.
|
375
|
-
@doc.image.current_path.
|
370
|
+
expect(@doc.save).to be_truthy
|
371
|
+
expect(File.exist?(public_path('uploads/test.jpeg'))).to be_truthy
|
372
|
+
expect(@doc.image).to be_an_instance_of(MongoUploader)
|
373
|
+
expect(@doc.image.current_path).to eq public_path('uploads/test.jpeg')
|
376
374
|
@doc.destroy
|
377
|
-
File.exist?(public_path('uploads/test.jpeg')).
|
375
|
+
expect(File.exist?(public_path('uploads/test.jpeg'))).to be_falsey
|
378
376
|
end
|
379
377
|
|
380
378
|
end
|
@@ -383,13 +381,13 @@ describe CarrierWave::Mongoid do
|
|
383
381
|
|
384
382
|
it "deletes the instance of MongoUser after save" do
|
385
383
|
@doc.save
|
386
|
-
MongoUser.count.
|
384
|
+
expect(MongoUser.count).to eq(1)
|
387
385
|
@doc.destroy
|
388
386
|
end
|
389
387
|
|
390
388
|
it "deletes the instance of MongoUser after save and then re-looking up the instance" do
|
391
389
|
@doc.save
|
392
|
-
MongoUser.count.
|
390
|
+
expect(MongoUser.count).to eq(1)
|
393
391
|
@doc = MongoUser.first
|
394
392
|
@doc.destroy
|
395
393
|
end
|
@@ -406,8 +404,8 @@ describe CarrierWave::Mongoid do
|
|
406
404
|
@class.field :foo
|
407
405
|
@doc = @class.new
|
408
406
|
@doc.image = stub_file('old.jpeg')
|
409
|
-
@doc.save.
|
410
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
407
|
+
expect(@doc.save).to be_truthy
|
408
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
411
409
|
end
|
412
410
|
|
413
411
|
after do
|
@@ -418,30 +416,30 @@ describe CarrierWave::Mongoid do
|
|
418
416
|
|
419
417
|
it "should remove old file if old file had a different path" do
|
420
418
|
@doc.image = stub_file('new.jpeg')
|
421
|
-
@doc.save.
|
422
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
423
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
419
|
+
expect(@doc.save).to be_truthy
|
420
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
421
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
424
422
|
end
|
425
423
|
|
426
424
|
it "should not remove old file if old file had a different path but config is false" do
|
427
|
-
@uploader.
|
425
|
+
allow(@uploader).to receive(:remove_previously_stored_files_after_update).and_return(false)
|
428
426
|
@doc.image = stub_file('new.jpeg')
|
429
|
-
@doc.save.
|
430
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
431
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
427
|
+
expect(@doc.save).to be_truthy
|
428
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
429
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
432
430
|
end
|
433
431
|
|
434
432
|
it "should not remove file if old file had the same path" do
|
435
433
|
@doc.image = stub_file('old.jpeg')
|
436
|
-
@doc.save.
|
437
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
434
|
+
expect(@doc.save).to be_truthy
|
435
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
438
436
|
end
|
439
437
|
|
440
438
|
it "should not remove file if validations fail on save" do
|
441
439
|
@class.validate { |r| r.errors.add :textfile, "FAIL!" }
|
442
440
|
@doc.image = stub_file('new.jpeg')
|
443
|
-
@doc.save.
|
444
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
441
|
+
expect(@doc.save).to be_falsey
|
442
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
445
443
|
end
|
446
444
|
end
|
447
445
|
|
@@ -455,91 +453,91 @@ describe CarrierWave::Mongoid do
|
|
455
453
|
|
456
454
|
@doc.image = stub_file('old.jpeg')
|
457
455
|
@doc.foo = "test"
|
458
|
-
@doc.save.
|
459
|
-
File.exists?(public_path('uploads/test.jpeg')).
|
460
|
-
@doc.image.read.
|
456
|
+
expect(@doc.save).to be_truthy
|
457
|
+
expect(File.exists?(public_path('uploads/test.jpeg'))).to be_truthy
|
458
|
+
expect(@doc.image.read).to eq "this is stuff"
|
461
459
|
end
|
462
460
|
|
463
461
|
it "should not remove file if old file had the same dynamic path" do
|
464
462
|
@doc.image = stub_file('test.jpeg')
|
465
|
-
@doc.save.
|
466
|
-
File.exists?(public_path('uploads/test.jpeg')).
|
463
|
+
expect(@doc.save).to be_truthy
|
464
|
+
expect(File.exists?(public_path('uploads/test.jpeg'))).to be_truthy
|
467
465
|
end
|
468
466
|
|
469
467
|
it "should remove old file if old file had a different dynamic path" do
|
470
468
|
@doc.foo = "new"
|
471
469
|
@doc.image = stub_file('test.jpeg')
|
472
|
-
@doc.save.
|
473
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
474
|
-
File.exists?(public_path('uploads/test.jpeg')).
|
470
|
+
expect(@doc.save).to be_truthy
|
471
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
472
|
+
expect(File.exists?(public_path('uploads/test.jpeg'))).to be_falsey
|
475
473
|
end
|
476
474
|
end
|
477
475
|
|
478
476
|
shared_examples "embedded documents" do
|
479
477
|
it "should remove old file if old file had a different path" do
|
480
478
|
@embedded_doc.image = stub_file('new.jpeg')
|
481
|
-
@embedded_doc.save.
|
482
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
483
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
479
|
+
expect(@embedded_doc.save).to be_truthy
|
480
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
481
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
484
482
|
end
|
485
483
|
|
486
484
|
it "should not remove old file if old file had a different path but config is false" do
|
487
|
-
@embedded_doc.image.
|
485
|
+
allow(@embedded_doc.image).to receive(:remove_previously_stored_files_after_update).and_return(false)
|
488
486
|
@embedded_doc.image = stub_file('new.jpeg')
|
489
|
-
@embedded_doc.save.
|
490
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
491
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
487
|
+
expect(@embedded_doc.save).to be_truthy
|
488
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
489
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
492
490
|
end
|
493
491
|
|
494
492
|
it "should not remove file if old file had the same path" do
|
495
493
|
@embedded_doc.image = stub_file('old.jpeg')
|
496
|
-
@embedded_doc.save.
|
497
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
494
|
+
expect(@embedded_doc.save).to be_truthy
|
495
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
498
496
|
end
|
499
497
|
|
500
498
|
it "should not remove file if validations fail on save" do
|
501
499
|
@embedded_doc_class.validate { |r| r.errors.add :textfile, "FAIL!" }
|
502
500
|
@embedded_doc.image = stub_file('new.jpeg')
|
503
|
-
@embedded_doc.save.
|
504
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
501
|
+
expect(@embedded_doc.save).to be_falsey
|
502
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
505
503
|
end
|
506
504
|
|
507
505
|
it "should not touch parent's dirty attributes" do
|
508
506
|
@class.field :title
|
509
507
|
@doc.title = "Title"
|
510
508
|
@embedded_doc.image = stub_file('new.jpeg')
|
511
|
-
@embedded_doc.save.
|
512
|
-
@doc.title.
|
509
|
+
expect(@embedded_doc.save).to be_truthy
|
510
|
+
expect(@doc.title).to eq "Title"
|
513
511
|
end
|
514
512
|
end
|
515
513
|
|
516
514
|
shared_examples "double embedded documents" do
|
517
515
|
it "should remove old file if old file had a different path" do
|
518
516
|
@double_embedded_doc.image = stub_file('new.jpeg')
|
519
|
-
@double_embedded_doc.save.
|
520
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
521
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
517
|
+
expect(@double_embedded_doc.save).to be_truthy
|
518
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
519
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
522
520
|
end
|
523
521
|
|
524
522
|
it "should not remove old file if old file had a different path but config is false" do
|
525
|
-
@double_embedded_doc.image.
|
523
|
+
allow(@double_embedded_doc.image).to receive(:remove_previously_stored_files_after_update).and_return(false)
|
526
524
|
@double_embedded_doc.image = stub_file('new.jpeg')
|
527
|
-
@double_embedded_doc.save.
|
528
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
529
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
525
|
+
expect(@double_embedded_doc.save).to be_truthy
|
526
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
527
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
530
528
|
end
|
531
529
|
|
532
530
|
it "should not remove file if old file had the same path" do
|
533
531
|
@double_embedded_doc.image = stub_file('old.jpeg')
|
534
|
-
@double_embedded_doc.save.
|
535
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
532
|
+
expect(@double_embedded_doc.save).to be_truthy
|
533
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
536
534
|
end
|
537
535
|
|
538
536
|
it "should not remove file if validations fail on save" do
|
539
537
|
@double_embedded_doc_class.validate { |r| r.errors.add :textfile, "FAIL!" }
|
540
538
|
@double_embedded_doc.image = stub_file('new.jpeg')
|
541
|
-
@double_embedded_doc.save.
|
542
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
539
|
+
expect(@double_embedded_doc.save).to be_falsey
|
540
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
543
541
|
end
|
544
542
|
|
545
543
|
end
|
@@ -559,7 +557,7 @@ describe CarrierWave::Mongoid do
|
|
559
557
|
@doc = @class.new
|
560
558
|
@embedded_doc = @doc.build_mongo_location
|
561
559
|
@embedded_doc.image = stub_file('old.jpeg')
|
562
|
-
@embedded_doc.save.
|
560
|
+
expect(@embedded_doc.save).to be_truthy
|
563
561
|
end
|
564
562
|
|
565
563
|
include_examples "embedded documents"
|
@@ -581,7 +579,7 @@ describe CarrierWave::Mongoid do
|
|
581
579
|
@doc = @class.new
|
582
580
|
@embedded_doc = @doc.build_mongo_location
|
583
581
|
@embedded_doc.image = stub_file('old.jpeg')
|
584
|
-
@embedded_doc.save.
|
582
|
+
expect(@embedded_doc.save).to be_truthy
|
585
583
|
end
|
586
584
|
|
587
585
|
include_examples "embedded documents"
|
@@ -603,7 +601,7 @@ describe CarrierWave::Mongoid do
|
|
603
601
|
@doc = @class.new
|
604
602
|
@embedded_doc = @doc.mongo_locations.build
|
605
603
|
@embedded_doc.image = stub_file('old.jpeg')
|
606
|
-
@embedded_doc.save.
|
604
|
+
expect(@embedded_doc.save).to be_truthy
|
607
605
|
end
|
608
606
|
|
609
607
|
include_examples "embedded documents"
|
@@ -611,26 +609,26 @@ describe CarrierWave::Mongoid do
|
|
611
609
|
it "attaches a new file to an existing document that had no file at first" do
|
612
610
|
doc = @class.new
|
613
611
|
doc.mongo_locations.build
|
614
|
-
doc.save.
|
612
|
+
expect(doc.save).to be_truthy
|
615
613
|
doc.reload
|
616
614
|
|
617
615
|
doc.mongo_locations.first.image = stub_file('test.jpeg')
|
618
|
-
doc.save.
|
616
|
+
expect(doc.save).to be_truthy
|
619
617
|
doc.reload
|
620
618
|
|
621
|
-
doc.mongo_locations.first[:image].
|
619
|
+
expect(doc.mongo_locations.first[:image]).to eq 'test.jpeg'
|
622
620
|
end
|
623
621
|
|
624
622
|
it "changes the file" do
|
625
623
|
@doc.update_attributes mongo_locations_attributes: { '0' => { _id: @embedded_doc._id, image: stub_file('test.jpeg') } }
|
626
624
|
@doc.reload
|
627
|
-
@doc.mongo_locations.first[:image].
|
625
|
+
expect(@doc.mongo_locations.first[:image]).to eq 'test.jpeg'
|
628
626
|
end
|
629
627
|
|
630
628
|
it "removes a file" do
|
631
629
|
@doc.update_attributes mongo_locations_attributes: { '0' => { _id: @embedded_doc._id, remove_image: "1" } }
|
632
630
|
@doc.reload
|
633
|
-
@doc.mongo_locations.first[:image].
|
631
|
+
expect(@doc.mongo_locations.first[:image]).to_not be_present
|
634
632
|
end
|
635
633
|
|
636
634
|
describe 'with double embedded documents' do
|
@@ -649,11 +647,11 @@ describe CarrierWave::Mongoid do
|
|
649
647
|
@doc = @class.new
|
650
648
|
@embedded_doc = @doc.mongo_locations.build
|
651
649
|
@embedded_doc.image = stub_file('old.jpeg')
|
652
|
-
@embedded_doc.save.
|
650
|
+
expect(@embedded_doc.save).to be_truthy
|
653
651
|
|
654
652
|
@double_embedded_doc = @embedded_doc.mongo_items.build
|
655
653
|
@double_embedded_doc.image = stub_file('old.jpeg')
|
656
|
-
@double_embedded_doc.save.
|
654
|
+
expect(@double_embedded_doc.save).to be_truthy
|
657
655
|
end
|
658
656
|
|
659
657
|
include_examples "double embedded documents"
|
@@ -676,7 +674,7 @@ describe CarrierWave::Mongoid do
|
|
676
674
|
@doc = @class.new
|
677
675
|
@embedded_doc = @doc.mongo_locations.build
|
678
676
|
@embedded_doc.image = stub_file('old.jpeg')
|
679
|
-
@embedded_doc.save.
|
677
|
+
expect(@embedded_doc.save).to be_truthy
|
680
678
|
end
|
681
679
|
|
682
680
|
include_examples "embedded documents"
|
@@ -697,11 +695,11 @@ describe CarrierWave::Mongoid do
|
|
697
695
|
@doc = @class.new
|
698
696
|
@embedded_doc = @doc.mongo_locations.build
|
699
697
|
@embedded_doc.image = stub_file('old.jpeg')
|
700
|
-
@embedded_doc.save.
|
698
|
+
expect(@embedded_doc.save).to be_truthy
|
701
699
|
|
702
700
|
@double_embedded_doc = @embedded_doc.mongo_items.build
|
703
701
|
@double_embedded_doc.image = stub_file('old.jpeg')
|
704
|
-
@double_embedded_doc.save.
|
702
|
+
expect(@double_embedded_doc.save).to be_truthy
|
705
703
|
end
|
706
704
|
|
707
705
|
include_examples "double embedded documents"
|
@@ -722,21 +720,21 @@ describe CarrierWave::Mongoid do
|
|
722
720
|
end
|
723
721
|
|
724
722
|
@doc = @class.new(mongo_locations_attributes: [{image: stub_file("old.jpeg")}])
|
725
|
-
@doc.save.
|
723
|
+
expect(@doc.save).to be_truthy
|
726
724
|
@embedded_doc = @doc.mongo_locations.first
|
727
725
|
end
|
728
726
|
|
729
727
|
it "should set the image on a save" do
|
730
728
|
@doc.reload
|
731
|
-
@doc.mongo_locations.first.image.path.
|
732
|
-
@embedded_doc.image.path.
|
729
|
+
expect(@doc.mongo_locations.first.image.path).to match(/old\.jpeg$/)
|
730
|
+
expect(@embedded_doc.image.path).to match(/old\.jpeg$/)
|
733
731
|
end
|
734
732
|
|
735
733
|
it "should update the image on update_attributes" do
|
736
|
-
@doc.update_attributes(mongo_locations_attributes: [{id: @embedded_doc.id, image: stub_file("new.jpeg")}]).
|
734
|
+
expect(@doc.update_attributes(mongo_locations_attributes: [{id: @embedded_doc.id, image: stub_file("new.jpeg")}])).to be_truthy
|
737
735
|
@doc.reload
|
738
|
-
@doc.mongo_locations.first.image.path.
|
739
|
-
@embedded_doc.image.path.
|
736
|
+
expect(@doc.mongo_locations.first.image.path).to match(/new\.jpeg$/)
|
737
|
+
expect(@embedded_doc.image.path).to match(/new\.jpeg$/)
|
740
738
|
end
|
741
739
|
end
|
742
740
|
end
|
@@ -749,9 +747,9 @@ describe CarrierWave::Mongoid do
|
|
749
747
|
@class = reset_mongo_class(@uploader)
|
750
748
|
@doc = @class.new
|
751
749
|
@doc.image = stub_file('old.jpeg')
|
752
|
-
@doc.save.
|
753
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
754
|
-
File.exists?(public_path('uploads/thumb_old.jpeg')).
|
750
|
+
expect(@doc.save).to be_truthy
|
751
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
752
|
+
expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_truthy
|
755
753
|
end
|
756
754
|
|
757
755
|
after do
|
@@ -760,18 +758,18 @@ describe CarrierWave::Mongoid do
|
|
760
758
|
|
761
759
|
it "should remove old file if old file had a different path" do
|
762
760
|
@doc.image = stub_file('new.jpeg')
|
763
|
-
@doc.save.
|
764
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
765
|
-
File.exists?(public_path('uploads/thumb_new.jpeg')).
|
766
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
767
|
-
File.exists?(public_path('uploads/thumb_old.jpeg')).
|
761
|
+
expect(@doc.save).to be_truthy
|
762
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
763
|
+
expect(File.exists?(public_path('uploads/thumb_new.jpeg'))).to be_truthy
|
764
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
765
|
+
expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_falsey
|
768
766
|
end
|
769
767
|
|
770
768
|
it "should not remove file if old file had the same path" do
|
771
769
|
@doc.image = stub_file('old.jpeg')
|
772
|
-
@doc.save.
|
773
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
774
|
-
File.exists?(public_path('uploads/thumb_old.jpeg')).
|
770
|
+
expect(@doc.save).to be_truthy
|
771
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
772
|
+
expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_truthy
|
775
773
|
end
|
776
774
|
end
|
777
775
|
|
@@ -785,9 +783,9 @@ describe CarrierWave::Mongoid do
|
|
785
783
|
@doc = @class.new
|
786
784
|
@doc.image = stub_file('old.jpeg')
|
787
785
|
@doc.textfile = stub_file('old.txt')
|
788
|
-
@doc.save.
|
789
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
790
|
-
File.exists?(public_path('uploads/old.txt')).
|
786
|
+
expect(@doc.save).to be_truthy
|
787
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
788
|
+
expect(File.exists?(public_path('uploads/old.txt'))).to be_truthy
|
791
789
|
end
|
792
790
|
|
793
791
|
after do
|
@@ -797,28 +795,28 @@ describe CarrierWave::Mongoid do
|
|
797
795
|
it "should remove old file1 and file2 if old file1 and file2 had a different paths" do
|
798
796
|
@doc.image = stub_file('new.jpeg')
|
799
797
|
@doc.textfile = stub_file('new.txt')
|
800
|
-
@doc.save.
|
801
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
802
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
803
|
-
File.exists?(public_path('uploads/new.txt')).
|
804
|
-
File.exists?(public_path('uploads/old.txt')).
|
798
|
+
expect(@doc.save).to be_truthy
|
799
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
800
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
801
|
+
expect(File.exists?(public_path('uploads/new.txt'))).to be_truthy
|
802
|
+
expect(File.exists?(public_path('uploads/old.txt'))).to be_falsey
|
805
803
|
end
|
806
804
|
|
807
805
|
it "should remove old file1 but not file2 if old file1 had a different path but old file2 has the same path" do
|
808
806
|
@doc.image = stub_file('new.jpeg')
|
809
807
|
@doc.textfile = stub_file('old.txt')
|
810
|
-
@doc.save.
|
811
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
812
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
813
|
-
File.exists?(public_path('uploads/old.txt')).
|
808
|
+
expect(@doc.save).to be_truthy
|
809
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
810
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
811
|
+
expect(File.exists?(public_path('uploads/old.txt'))).to be_truthy
|
814
812
|
end
|
815
813
|
|
816
814
|
it "should not remove file1 or file2 if file1 and file2 have the same paths" do
|
817
815
|
@doc.image = stub_file('old.jpeg')
|
818
816
|
@doc.textfile = stub_file('old.txt')
|
819
|
-
@doc.save.
|
820
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
821
|
-
File.exists?(public_path('uploads/old.txt')).
|
817
|
+
expect(@doc.save).to be_truthy
|
818
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
819
|
+
expect(File.exists?(public_path('uploads/old.txt'))).to be_truthy
|
822
820
|
end
|
823
821
|
end
|
824
822
|
|
@@ -830,8 +828,8 @@ describe CarrierWave::Mongoid do
|
|
830
828
|
@class.mount_uploader(:avatar, @uploader1, :mount_on => :another_image)
|
831
829
|
@doc = @class.new
|
832
830
|
@doc.avatar = stub_file('old.jpeg')
|
833
|
-
@doc.save.
|
834
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
831
|
+
expect(@doc.save).to be_truthy
|
832
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
835
833
|
end
|
836
834
|
|
837
835
|
after do
|
@@ -840,15 +838,15 @@ describe CarrierWave::Mongoid do
|
|
840
838
|
|
841
839
|
it "should remove old file if old file had a different path" do
|
842
840
|
@doc.avatar = stub_file('new.jpeg')
|
843
|
-
@doc.save.
|
844
|
-
File.exists?(public_path('uploads/new.jpeg')).
|
845
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
841
|
+
expect(@doc.save).to be_truthy
|
842
|
+
expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
|
843
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
|
846
844
|
end
|
847
845
|
|
848
846
|
it "should not remove file if old file had the same path" do
|
849
847
|
@doc.avatar = stub_file('old.jpeg')
|
850
|
-
@doc.save.
|
851
|
-
File.exists?(public_path('uploads/old.jpeg')).
|
848
|
+
expect(@doc.save).to be_truthy
|
849
|
+
expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
|
852
850
|
end
|
853
851
|
end
|
854
852
|
|
@@ -864,21 +862,21 @@ describe CarrierWave::Mongoid do
|
|
864
862
|
end
|
865
863
|
|
866
864
|
@doc = @class.new(image: stub_file("old.jpeg"))
|
867
|
-
@doc.save.
|
865
|
+
expect(@doc.save).to be_truthy
|
868
866
|
end
|
869
867
|
|
870
868
|
it "should not remove underlying image after #destroy" do
|
871
|
-
@doc.destroy.
|
872
|
-
@class.count.
|
873
|
-
@class.deleted.count.
|
874
|
-
File.exist?(public_path('uploads/old.jpeg')).
|
869
|
+
expect(@doc.destroy).to be_truthy
|
870
|
+
expect(@class.count).to eql(0)
|
871
|
+
expect(@class.deleted.count).to eql(1)
|
872
|
+
expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
|
875
873
|
end
|
876
874
|
|
877
875
|
it "should remove underlying image after #destroy!" do
|
878
|
-
@doc.destroy
|
879
|
-
@class.count.
|
880
|
-
@class.deleted.count.
|
881
|
-
File.exist?(public_path('uploads/old.jpeg')).
|
876
|
+
expect(@doc.destroy!).to be_truthy
|
877
|
+
expect(@class.count).to eql(0)
|
878
|
+
expect(@class.deleted.count).to eql(0)
|
879
|
+
expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
|
882
880
|
end
|
883
881
|
end
|
884
882
|
end
|
@@ -893,14 +891,14 @@ describe CarrierWave::Mongoid do
|
|
893
891
|
end
|
894
892
|
|
895
893
|
it "serializes the correct values" do
|
896
|
-
@event.serializable_hash["image"]["url"].
|
897
|
-
@event.serializable_hash["textfile"]["url"].
|
894
|
+
expect(@event.serializable_hash["image"]["url"]).to match(/old\.jpeg$/)
|
895
|
+
expect(@event.serializable_hash["textfile"]["url"]).to match(/old\.txt$/)
|
898
896
|
end
|
899
897
|
|
900
898
|
it "should have JSON for each uploader" do
|
901
899
|
parsed = JSON.parse(@event.to_json)
|
902
|
-
parsed["image"]["url"].
|
903
|
-
parsed["textfile"]["url"].
|
900
|
+
expect(parsed["image"]["url"]).to match(/old\.jpeg$/)
|
901
|
+
expect(parsed["textfile"]["url"]).to match(/old\.txt$/)
|
904
902
|
end
|
905
903
|
end
|
906
904
|
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,10 @@ Mongoid.configure do |config|
|
|
11
11
|
config.connect_to('carrierwave_test')
|
12
12
|
end
|
13
13
|
|
14
|
+
if defined? Mongo
|
15
|
+
Mongo::Logger.level = ::Logger::INFO
|
16
|
+
end
|
17
|
+
|
14
18
|
def file_path( *paths )
|
15
19
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
16
20
|
end
|
@@ -25,8 +29,7 @@ module CarrierWave
|
|
25
29
|
module Test
|
26
30
|
module MockFiles
|
27
31
|
def stub_file(filename, mime_type=nil, fake_name=nil)
|
28
|
-
|
29
|
-
return f
|
32
|
+
File.open(file_path(filename))
|
30
33
|
end
|
31
34
|
|
32
35
|
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
@@ -35,9 +38,9 @@ module CarrierWave
|
|
35
38
|
t = Tempfile.new(filename)
|
36
39
|
FileUtils.copy_file(file_path(filename), t.path)
|
37
40
|
|
38
|
-
t.
|
39
|
-
|
40
|
-
|
41
|
+
allow(t).to receive(:local_path).and_return("")
|
42
|
+
allow(t).to receive(:original_filename).and_return(filename || fake_name)
|
43
|
+
allow(t).to receive(:content_type).and_return(mime_type)
|
41
44
|
|
42
45
|
return t
|
43
46
|
end
|
@@ -76,4 +79,5 @@ end
|
|
76
79
|
RSpec.configure do |config|
|
77
80
|
config.include CarrierWave::Test::MockFiles
|
78
81
|
config.include CarrierWave::Test::I18nHelpers
|
82
|
+
config.color = true
|
79
83
|
end
|
@@ -1,51 +1,48 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
2
|
require 'spec_helper'
|
5
3
|
|
6
|
-
|
7
4
|
shared_examples_for "a GridFS connection" do
|
8
5
|
describe '#store!' do
|
9
6
|
before do
|
10
|
-
@uploader.
|
7
|
+
allow(@uploader).to receive(:store_path).and_return('uploads/bar.txt')
|
11
8
|
@grid_fs_file = @storage.store!(@file)
|
12
9
|
end
|
13
10
|
|
14
11
|
it "should upload the file to gridfs" do
|
15
|
-
@grid['uploads/bar.txt'].data.
|
12
|
+
expect(@grid['uploads/bar.txt'].data).to eq 'this is stuff'
|
16
13
|
end
|
17
14
|
|
18
15
|
it "should upload the file to gridfs" do
|
19
|
-
@grid['uploads/bar.txt'].data.
|
16
|
+
expect(@grid['uploads/bar.txt'].data).to eq 'this is stuff'
|
20
17
|
end
|
21
18
|
|
22
19
|
it "should have the same path that it was stored as" do
|
23
|
-
@grid_fs_file.path.
|
20
|
+
expect(@grid_fs_file.path).to eq 'uploads/bar.txt'
|
24
21
|
end
|
25
22
|
|
26
23
|
it "should read the contents of the file" do
|
27
|
-
@grid_fs_file.read.
|
24
|
+
expect(@grid_fs_file.read).to eq "this is stuff"
|
28
25
|
end
|
29
26
|
|
30
27
|
it "should not have a URL" do
|
31
|
-
@grid_fs_file.url.
|
28
|
+
expect(@grid_fs_file.url).to be_nil
|
32
29
|
end
|
33
30
|
|
34
31
|
it "should be deletable" do
|
35
32
|
@grid_fs_file.delete
|
36
|
-
@grid['uploads/bar.txt'].
|
33
|
+
expect(@grid['uploads/bar.txt']).to be_nil
|
37
34
|
end
|
38
35
|
|
39
36
|
it "should store the content type on GridFS" do
|
40
|
-
@grid_fs_file.content_type.
|
37
|
+
expect(@grid_fs_file.content_type).to eq 'text/plain'
|
41
38
|
end
|
42
39
|
|
43
40
|
it "should have a file length" do
|
44
|
-
@grid_fs_file.file_length.
|
41
|
+
expect(@grid_fs_file.file_length).to eq 13
|
45
42
|
end
|
46
43
|
|
47
44
|
it "should have a file md5" do
|
48
|
-
@grid_fs_file.md5.
|
45
|
+
expect(@grid_fs_file.md5).to eq 'bf8456578232907ce3136ba776e1a40d'
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
@@ -53,52 +50,52 @@ shared_examples_for "a GridFS connection" do
|
|
53
50
|
before do
|
54
51
|
@grid.clear
|
55
52
|
@grid['uploads/bar.txt'] = StringIO.new('A test, 1234')
|
56
|
-
@uploader.
|
53
|
+
allow(@uploader).to receive(:store_path).with('bar.txt').and_return('uploads/bar.txt')
|
57
54
|
@grid_fs_file = @storage.retrieve!('bar.txt')
|
58
55
|
end
|
59
56
|
|
60
57
|
it "should retrieve the file contents from gridfs" do
|
61
|
-
@grid_fs_file.read.chomp.
|
58
|
+
expect(@grid_fs_file.read.chomp).to eq "A test, 1234"
|
62
59
|
end
|
63
60
|
|
64
61
|
it "should have the same path that it was stored as" do
|
65
|
-
@grid_fs_file.path.
|
62
|
+
expect(@grid_fs_file.path).to eq 'uploads/bar.txt'
|
66
63
|
end
|
67
64
|
|
68
65
|
it "should not have a URL unless access_url is set" do
|
69
|
-
@grid_fs_file.url.
|
66
|
+
expect(@grid_fs_file.url).to be_nil
|
70
67
|
end
|
71
68
|
|
72
69
|
it "should return a relative URL path if access_url is set to the root path" do
|
73
|
-
@uploader.
|
74
|
-
@grid_fs_file.url.
|
70
|
+
allow(@uploader).to receive(:grid_fs_access_url).and_return("/")
|
71
|
+
expect(@grid_fs_file.url).to eq "/uploads/bar.txt"
|
75
72
|
end
|
76
73
|
|
77
74
|
it "should return a URL path if access_url is set to a file path" do
|
78
|
-
@uploader.
|
79
|
-
@grid_fs_file.url.
|
75
|
+
allow(@uploader).to receive(:grid_fs_access_url).and_return("/image/show")
|
76
|
+
expect(@grid_fs_file.url).to eq "/image/show/uploads/bar.txt"
|
80
77
|
end
|
81
78
|
|
82
79
|
it "should return an absolute URL if access_url is set to an absolute URL" do
|
83
|
-
@uploader.
|
84
|
-
@grid_fs_file.url.
|
80
|
+
allow(@uploader).to receive(:grid_fs_access_url).and_return("http://example.com/images/")
|
81
|
+
expect(@grid_fs_file.url).to eq "http://example.com/images/uploads/bar.txt"
|
85
82
|
end
|
86
83
|
|
87
84
|
it "should be deletable" do
|
88
85
|
@grid_fs_file.delete
|
89
|
-
@grid['uploads/bar.txt'].
|
86
|
+
expect(@grid['uploads/bar.txt']).to be_nil
|
90
87
|
end
|
91
88
|
end
|
92
89
|
|
93
90
|
describe '#retrieve! on a store_dir with leading slash' do
|
94
91
|
before do
|
95
|
-
@uploader.
|
92
|
+
allow(@uploader).to receive(:store_path).with('bar.txt').and_return('/uploads/bar.txt')
|
96
93
|
@grid_fs_file = @storage.retrieve!('bar.txt')
|
97
94
|
end
|
98
95
|
|
99
96
|
it "should return a relative URL path if access_url is set to the root path" do
|
100
|
-
@uploader.
|
101
|
-
@grid_fs_file.url.
|
97
|
+
allow(@uploader).to receive(:grid_fs_access_url).and_return("/")
|
98
|
+
expect(@grid_fs_file.url).to eq "/uploads/bar.txt"
|
102
99
|
end
|
103
100
|
end
|
104
101
|
|
@@ -108,12 +105,12 @@ describe CarrierWave::Storage::GridFS do
|
|
108
105
|
|
109
106
|
before do
|
110
107
|
@uploader = double('an uploader')
|
111
|
-
@uploader.
|
108
|
+
allow(@uploader).to receive(:grid_fs_access_url).and_return(nil)
|
112
109
|
end
|
113
110
|
|
114
111
|
context "when reusing an existing connection manually" do
|
115
112
|
before do
|
116
|
-
@uploader.
|
113
|
+
allow(@uploader).to receive(:grid_fs_connection).and_return(@database)
|
117
114
|
|
118
115
|
@grid = ::Mongoid::GridFs
|
119
116
|
|
@@ -146,11 +143,8 @@ describe CarrierWave::Storage::GridFS do
|
|
146
143
|
end
|
147
144
|
|
148
145
|
it "recreates versions stored remotely without error" do
|
149
|
-
|
150
|
-
|
151
|
-
}.should_not raise_error
|
152
|
-
|
153
|
-
@versioned.should be_present
|
146
|
+
expect { @versioned.recreate_versions! }.not_to raise_error
|
147
|
+
expect(@versioned).to be_present
|
154
148
|
end
|
155
149
|
end
|
156
150
|
|
@@ -172,10 +166,7 @@ describe CarrierWave::Storage::GridFS do
|
|
172
166
|
end
|
173
167
|
|
174
168
|
it "resizes the file with out error" do
|
175
|
-
|
176
|
-
@versioned.resize_to_fill(200, 200)
|
177
|
-
}.should_not raise_error
|
178
|
-
|
169
|
+
expect { @versioned.resize_to_fill(200, 200) }.not_to raise_error
|
179
170
|
end
|
180
171
|
end
|
181
172
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: carrierwave
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: 0.8.0
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.12.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: 0.8.0
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.12.0
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: mongoid
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,28 +77,28 @@ dependencies:
|
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 3.4.0
|
81
81
|
type: :development
|
82
82
|
prerelease: false
|
83
83
|
version_requirements: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: 3.4.0
|
88
88
|
- !ruby/object:Gem::Dependency
|
89
89
|
name: rake
|
90
90
|
requirement: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
94
|
+
version: 11.1.2
|
95
95
|
type: :development
|
96
96
|
prerelease: false
|
97
97
|
version_requirements: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
99
|
- - "~>"
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 11.1.2
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: mini_magick
|
104
104
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- README.md
|
142
142
|
- Rakefile
|
143
143
|
- carrierwave-mongoid.gemspec
|
144
|
+
- gemfiles/carrierwave-0.10.gemfile
|
144
145
|
- gemfiles/carrierwave-0.9.gemfile
|
145
146
|
- gemfiles/carrierwave-master.gemfile
|
146
147
|
- gemfiles/mongoid-3.1.gemfile
|
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
181
|
version: '0'
|
181
182
|
requirements: []
|
182
183
|
rubyforge_project: carrierwave-mongoid
|
183
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.6.1
|
184
185
|
signing_key:
|
185
186
|
specification_version: 4
|
186
187
|
summary: Mongoid support for CarrierWave
|