carrierwave-mongoid 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/mongoid_spec.rb CHANGED
@@ -10,13 +10,6 @@ def reset_mongo_class(uploader = MongoUploader)
10
10
  end
11
11
  end
12
12
 
13
- def define_mongo_class(class_name, &block)
14
- Object.send(:remove_const, class_name) rescue nil
15
- klass = Object.const_set(class_name, Class.new)
16
- klass.class_eval(&block)
17
- klass
18
- end
19
-
20
13
  class MongoUploader < CarrierWave::Uploader::Base; end
21
14
  class AnotherMongoUploader < CarrierWave::Uploader::Base; end
22
15
 
@@ -175,7 +168,7 @@ describe CarrierWave::Mongoid do
175
168
  expect(@doc.image).to be_an_instance_of(MongoUploader)
176
169
  end
177
170
 
178
- it "should write nothing to the database, to prevent overriden filenames to fail because of unassigned attributes" do
171
+ it "should write nothing to the database, to prevent overridden filenames to fail because of unassigned attributes" do
179
172
  expect(@doc[:image]).to be_nil
180
173
  end
181
174
 
@@ -400,6 +393,24 @@ describe CarrierWave::Mongoid do
400
393
 
401
394
  end
402
395
 
396
+ describe '#reload' do
397
+
398
+ before do
399
+ @mongo_user_klass = reset_mongo_class
400
+ @doc = @mongo_user_klass.new
401
+ @doc.save
402
+ end
403
+
404
+ it 'reset cached value on reload' do
405
+ new = @mongo_user_klass.find(@doc.id)
406
+ new.image = stub_file('test.jpeg')
407
+ new.save
408
+
409
+ expect(@doc.reload.image).to_not be_blank
410
+ end
411
+
412
+ end
413
+
403
414
  describe '#mount_uploader removing old files' do
404
415
 
405
416
  before do
@@ -409,7 +420,7 @@ describe CarrierWave::Mongoid do
409
420
  @doc = @class.new
410
421
  @doc.image = stub_file('old.jpeg')
411
422
  expect(@doc.save).to be_truthy
412
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
423
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
413
424
  end
414
425
 
415
426
  after do
@@ -421,33 +432,33 @@ describe CarrierWave::Mongoid do
421
432
  it "should remove old file if old file had a different path" do
422
433
  @doc.image = stub_file('new.jpeg')
423
434
  expect(@doc.save).to be_truthy
424
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
425
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
435
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
436
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
426
437
  end
427
438
 
428
439
  it "should not remove old file if old file had a different path but config is false" do
429
440
  @doc.image.class.remove_previously_stored_files_after_update = false
430
441
  @doc.image = stub_file('new.jpeg')
431
442
  expect(@doc.save).to be_truthy
432
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
433
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
443
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
444
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
434
445
  end
435
446
 
436
447
  it "should not remove file if old file had the same path" do
437
448
  @doc.image = stub_file('old.jpeg')
438
449
  expect(@doc.save).to be_truthy
439
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
450
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
440
451
  end
441
452
 
442
453
  it "should not remove file if validations fail on save" do
443
454
  @class.validate { |r| r.errors.add :textfile, "FAIL!" }
444
455
  @doc.image = stub_file('new.jpeg')
445
456
  expect(@doc.save).to be_falsey
446
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
457
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
447
458
  end
448
459
  end
449
460
 
450
- describe 'with an overriden filename' do
461
+ describe 'with an overridden filename' do
451
462
  before do
452
463
  @uploader.class_eval do
453
464
  def filename
@@ -458,22 +469,22 @@ describe CarrierWave::Mongoid do
458
469
  @doc.image = stub_file('old.jpeg')
459
470
  @doc.foo = "test"
460
471
  expect(@doc.save).to be_truthy
461
- expect(File.exists?(public_path('uploads/test.jpeg'))).to be_truthy
472
+ expect(File.exist?(public_path('uploads/test.jpeg'))).to be_truthy
462
473
  expect(@doc.image.read).to eq "this is stuff"
463
474
  end
464
475
 
465
476
  it "should not remove file if old file had the same dynamic path" do
466
477
  @doc.image = stub_file('test.jpeg')
467
478
  expect(@doc.save).to be_truthy
468
- expect(File.exists?(public_path('uploads/test.jpeg'))).to be_truthy
479
+ expect(File.exist?(public_path('uploads/test.jpeg'))).to be_truthy
469
480
  end
470
481
 
471
482
  it "should remove old file if old file had a different dynamic path" do
472
483
  @doc.foo = "new"
473
484
  @doc.image = stub_file('test.jpeg')
474
485
  expect(@doc.save).to be_truthy
475
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
476
- expect(File.exists?(public_path('uploads/test.jpeg'))).to be_falsey
486
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
487
+ expect(File.exist?(public_path('uploads/test.jpeg'))).to be_falsey
477
488
  end
478
489
  end
479
490
 
@@ -481,29 +492,29 @@ describe CarrierWave::Mongoid do
481
492
  it "should remove old file if old file had a different path" do
482
493
  @embedded_doc.image = stub_file('new.jpeg')
483
494
  expect(@embedded_doc.save).to be_truthy
484
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
485
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
495
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
496
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
486
497
  end
487
498
 
488
499
  it "should not remove old file if old file had a different path but config is false" do
489
500
  @embedded_doc.image.class.remove_previously_stored_files_after_update = false
490
501
  @embedded_doc.image = stub_file('new.jpeg')
491
502
  expect(@embedded_doc.save).to be_truthy
492
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
493
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
503
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
504
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
494
505
  end
495
506
 
496
507
  it "should not remove file if old file had the same path" do
497
508
  @embedded_doc.image = stub_file('old.jpeg')
498
509
  expect(@embedded_doc.save).to be_truthy
499
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
510
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
500
511
  end
501
512
 
502
513
  it "should not remove file if validations fail on save" do
503
514
  @embedded_doc_class.validate { |r| r.errors.add :textfile, "FAIL!" }
504
515
  @embedded_doc.image = stub_file('new.jpeg')
505
516
  expect(@embedded_doc.save).to be_falsey
506
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
517
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
507
518
  end
508
519
 
509
520
  it "should not touch parent's dirty attributes" do
@@ -519,29 +530,29 @@ describe CarrierWave::Mongoid do
519
530
  it "should remove old file if old file had a different path" do
520
531
  @double_embedded_doc.image = stub_file('new.jpeg')
521
532
  expect(@double_embedded_doc.save).to be_truthy
522
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
523
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
533
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
534
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
524
535
  end
525
536
 
526
537
  it "should not remove old file if old file had a different path but config is false" do
527
538
  @double_embedded_doc.image.class.remove_previously_stored_files_after_update = false
528
539
  @double_embedded_doc.image = stub_file('new.jpeg')
529
540
  expect(@double_embedded_doc.save).to be_truthy
530
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
531
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
541
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
542
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
532
543
  end
533
544
 
534
545
  it "should not remove file if old file had the same path" do
535
546
  @double_embedded_doc.image = stub_file('old.jpeg')
536
547
  expect(@double_embedded_doc.save).to be_truthy
537
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
548
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
538
549
  end
539
550
 
540
551
  it "should not remove file if validations fail on save" do
541
552
  @double_embedded_doc_class.validate { |r| r.errors.add :textfile, "FAIL!" }
542
553
  @double_embedded_doc.image = stub_file('new.jpeg')
543
554
  expect(@double_embedded_doc.save).to be_falsey
544
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
555
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
545
556
  end
546
557
 
547
558
  end
@@ -752,8 +763,8 @@ describe CarrierWave::Mongoid do
752
763
  @doc = @class.new
753
764
  @doc.image = stub_file('old.jpeg')
754
765
  expect(@doc.save).to be_truthy
755
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
756
- expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_truthy
766
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
767
+ expect(File.exist?(public_path('uploads/thumb_old.jpeg'))).to be_truthy
757
768
  end
758
769
 
759
770
  after do
@@ -763,17 +774,17 @@ describe CarrierWave::Mongoid do
763
774
  it "should remove old file if old file had a different path" do
764
775
  @doc.image = stub_file('new.jpeg')
765
776
  expect(@doc.save).to be_truthy
766
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
767
- expect(File.exists?(public_path('uploads/thumb_new.jpeg'))).to be_truthy
768
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
769
- expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_falsey
777
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
778
+ expect(File.exist?(public_path('uploads/thumb_new.jpeg'))).to be_truthy
779
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
780
+ expect(File.exist?(public_path('uploads/thumb_old.jpeg'))).to be_falsey
770
781
  end
771
782
 
772
783
  it "should not remove file if old file had the same path" do
773
784
  @doc.image = stub_file('old.jpeg')
774
785
  expect(@doc.save).to be_truthy
775
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
776
- expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_truthy
786
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
787
+ expect(File.exist?(public_path('uploads/thumb_old.jpeg'))).to be_truthy
777
788
  end
778
789
  end
779
790
 
@@ -788,8 +799,8 @@ describe CarrierWave::Mongoid do
788
799
  @doc.image = stub_file('old.jpeg')
789
800
  @doc.textfile = stub_file('old.txt')
790
801
  expect(@doc.save).to be_truthy
791
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
792
- expect(File.exists?(public_path('uploads/old.txt'))).to be_truthy
802
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
803
+ expect(File.exist?(public_path('uploads/old.txt'))).to be_truthy
793
804
  end
794
805
 
795
806
  after do
@@ -800,27 +811,27 @@ describe CarrierWave::Mongoid do
800
811
  @doc.image = stub_file('new.jpeg')
801
812
  @doc.textfile = stub_file('new.txt')
802
813
  expect(@doc.save).to be_truthy
803
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
804
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
805
- expect(File.exists?(public_path('uploads/new.txt'))).to be_truthy
806
- expect(File.exists?(public_path('uploads/old.txt'))).to be_falsey
814
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
815
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
816
+ expect(File.exist?(public_path('uploads/new.txt'))).to be_truthy
817
+ expect(File.exist?(public_path('uploads/old.txt'))).to be_falsey
807
818
  end
808
819
 
809
820
  it "should remove old file1 but not file2 if old file1 had a different path but old file2 has the same path" do
810
821
  @doc.image = stub_file('new.jpeg')
811
822
  @doc.textfile = stub_file('old.txt')
812
823
  expect(@doc.save).to be_truthy
813
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
814
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
815
- expect(File.exists?(public_path('uploads/old.txt'))).to be_truthy
824
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
825
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
826
+ expect(File.exist?(public_path('uploads/old.txt'))).to be_truthy
816
827
  end
817
828
 
818
829
  it "should not remove file1 or file2 if file1 and file2 have the same paths" do
819
830
  @doc.image = stub_file('old.jpeg')
820
831
  @doc.textfile = stub_file('old.txt')
821
832
  expect(@doc.save).to be_truthy
822
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
823
- expect(File.exists?(public_path('uploads/old.txt'))).to be_truthy
833
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
834
+ expect(File.exist?(public_path('uploads/old.txt'))).to be_truthy
824
835
  end
825
836
  end
826
837
 
@@ -833,7 +844,7 @@ describe CarrierWave::Mongoid do
833
844
  @doc = @class.new
834
845
  @doc.avatar = stub_file('old.jpeg')
835
846
  expect(@doc.save).to be_truthy
836
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
847
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
837
848
  end
838
849
 
839
850
  after do
@@ -843,14 +854,14 @@ describe CarrierWave::Mongoid do
843
854
  it "should remove old file if old file had a different path" do
844
855
  @doc.avatar = stub_file('new.jpeg')
845
856
  expect(@doc.save).to be_truthy
846
- expect(File.exists?(public_path('uploads/new.jpeg'))).to be_truthy
847
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_falsey
857
+ expect(File.exist?(public_path('uploads/new.jpeg'))).to be_truthy
858
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_falsey
848
859
  end
849
860
 
850
861
  it "should not remove file if old file had the same path" do
851
862
  @doc.avatar = stub_file('old.jpeg')
852
863
  expect(@doc.save).to be_truthy
853
- expect(File.exists?(public_path('uploads/old.jpeg'))).to be_truthy
864
+ expect(File.exist?(public_path('uploads/old.jpeg'))).to be_truthy
854
865
  end
855
866
  end
856
867
 
data/spec/spec_helper.rb CHANGED
@@ -81,3 +81,10 @@ RSpec.configure do |config|
81
81
  config.include CarrierWave::Test::I18nHelpers
82
82
  config.color = true
83
83
  end
84
+
85
+ def define_mongo_class(class_name, &block)
86
+ Object.send(:remove_const, class_name) rescue nil
87
+ klass = Object.const_set(class_name, Class.new)
88
+ klass.class_eval(&block)
89
+ klass
90
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
8
8
  - Trevor Turk
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-23 00:00:00.000000000 Z
12
+ date: 2023-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '3.0'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '8.0'
43
+ version: '9.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: '3.0'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '8.0'
53
+ version: '9.0'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: mongoid-grid_fs
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -77,28 +77,28 @@ dependencies:
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: 3.4.0
80
+ version: '3.4'
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: 3.4.0
87
+ version: '3.4'
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: 11.1.2
94
+ version: 12.3.3
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: 11.1.2
101
+ version: 12.3.3
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: mini_magick
104
104
  requirement: !ruby/object:Gem::Requirement
@@ -134,8 +134,8 @@ executables: []
134
134
  extensions: []
135
135
  extra_rdoc_files: []
136
136
  files:
137
+ - ".github/workflows/ci.yml"
137
138
  - ".gitignore"
138
- - ".travis.yml"
139
139
  - Gemfile
140
140
  - LICENSE
141
141
  - README.md
@@ -147,15 +147,19 @@ files:
147
147
  - gemfiles/carrierwave-1.2.gemfile
148
148
  - gemfiles/carrierwave-1.3.gemfile
149
149
  - gemfiles/carrierwave-2.0.gemfile
150
+ - gemfiles/carrierwave-2.1.gemfile
151
+ - gemfiles/carrierwave-2.2.gemfile
150
152
  - gemfiles/mongoid-3.gemfile
151
153
  - gemfiles/mongoid-4.gemfile
152
154
  - gemfiles/mongoid-5.gemfile
153
155
  - gemfiles/mongoid-6.gemfile
154
156
  - gemfiles/mongoid-7.gemfile
157
+ - gemfiles/mongoid-8.gemfile
155
158
  - lib/carrierwave/mongoid.rb
156
159
  - lib/carrierwave/mongoid/version.rb
157
160
  - lib/carrierwave/storage/grid_fs.rb
158
161
  - log/.gitkeep
162
+ - spec/carrierwave/mongoid/mount_uploaders_spec.rb
159
163
  - spec/fixtures/new.jpeg
160
164
  - spec/fixtures/new.txt
161
165
  - spec/fixtures/old.jpeg
@@ -170,7 +174,7 @@ homepage: https://github.com/carrierwaveuploader/carrierwave-mongoid
170
174
  licenses:
171
175
  - MIT
172
176
  metadata: {}
173
- post_install_message:
177
+ post_install_message:
174
178
  rdoc_options: []
175
179
  require_paths:
176
180
  - lib
@@ -185,11 +189,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
189
  - !ruby/object:Gem::Version
186
190
  version: '0'
187
191
  requirements: []
188
- rubygems_version: 3.0.3
189
- signing_key:
192
+ rubygems_version: 3.3.17
193
+ signing_key:
190
194
  specification_version: 4
191
195
  summary: Mongoid support for CarrierWave
192
196
  test_files:
197
+ - spec/carrierwave/mongoid/mount_uploaders_spec.rb
193
198
  - spec/fixtures/new.jpeg
194
199
  - spec/fixtures/new.txt
195
200
  - spec/fixtures/old.jpeg
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- sudo: false
2
- services: mongodb
3
-
4
- notifications:
5
- email: false
6
-
7
- language: ruby
8
- cache: bundler
9
- rvm:
10
- - 2.3
11
- - 2.4
12
- - 2.5
13
- - 2.6
14
-
15
- gemfile:
16
- - Gemfile
17
- - gemfiles/carrierwave-0.10.gemfile
18
- - gemfiles/carrierwave-0.11.gemfile
19
- - gemfiles/carrierwave-1.1.gemfile
20
- - gemfiles/carrierwave-1.2.gemfile
21
- - gemfiles/carrierwave-1.3.gemfile
22
- - gemfiles/carrierwave-2.0.gemfile
23
- - gemfiles/mongoid-3.gemfile
24
- - gemfiles/mongoid-4.gemfile
25
- - gemfiles/mongoid-5.gemfile
26
- - gemfiles/mongoid-6.gemfile
27
- - gemfiles/mongoid-7.gemfile
28
-
29
- matrix:
30
- fast_finish: true