File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -72,9 +72,10 @@ def cache_names
72
72
end
73
73
74
74
def cache_names = ( cache_names )
75
+ cache_names = cache_names . reject ( &:blank? )
75
76
return if cache_names . blank?
76
77
clear_unstaged
77
- cache_names . map do |cache_name |
78
+ cache_names . each do |cache_name |
78
79
begin
79
80
uploader = blank_uploader
80
81
uploader . retrieve_from_cache! ( cache_name )
@@ -91,7 +92,7 @@ def remote_urls=(urls)
91
92
@remote_urls = urls
92
93
93
94
clear_unstaged
94
- urls . zip ( remote_request_headers || [ ] ) . map do |url , header |
95
+ urls . zip ( remote_request_headers || [ ] ) . each do |url , header |
95
96
handle_error do
96
97
uploader = blank_uploader
97
98
uploader . download! ( url , header || { } )
Original file line number Diff line number Diff line change @@ -487,6 +487,18 @@ def monkey
487
487
expect ( instance . images . map ( &:cache_name ) ) . to eq ( [ '1369894322-123-0123-1234/test.jpg' ] )
488
488
end
489
489
end
490
+
491
+ context "when an empty string is assigned" do
492
+ before do
493
+ instance . images = [ test_file_stub ]
494
+ instance . store_images!
495
+ instance . images_cache = [ '' ] . to_json
496
+ end
497
+
498
+ it "does not write over a previously stored file" do
499
+ expect ( instance . images [ 0 ] . current_path ) . to match ( /test.jpg$/ )
500
+ end
501
+ end
490
502
end
491
503
492
504
describe "#remote_images_urls" do
@@ -565,6 +577,22 @@ def monkey
565
577
it { is_expected . to match ( /portrait.jpg$/ ) }
566
578
end
567
579
580
+ context "when an empty string is assigned" do
581
+ subject { images [ 0 ] . current_path }
582
+
583
+ let ( :remote_images_url ) { [ "" ] }
584
+
585
+ before do
586
+ instance . images = [ stub_file ( "portrait.jpg" ) ]
587
+ instance . store_images!
588
+ instance . remote_images_urls = remote_images_url
589
+ end
590
+
591
+ it "does not write over a previously stored file" do
592
+ is_expected . to match ( /portrait.jpg$/ )
593
+ end
594
+ end
595
+
568
596
context "if a file fails to be downloaded" do
569
597
let ( :remote_images_url ) { [ "http://www.example.com/test.txt" , "http://www.example.com/test.jpg" ] }
570
598
Original file line number Diff line number Diff line change @@ -288,6 +288,13 @@ def default_url
288
288
@instance . image_cache = '1369894322-123-0123-1234/monkey.jpg'
289
289
expect ( @instance . image . current_path ) . to match ( /test.jpg$/ )
290
290
end
291
+
292
+ it "should not clear a previously stored file when an empty string is assigned" do
293
+ @instance . image = stub_file ( 'test.jpg' )
294
+ @instance . image . store!
295
+ @instance . image_cache = ''
296
+ expect ( @instance . image . current_path ) . to match ( /test.jpg$/ )
297
+ end
291
298
end
292
299
293
300
describe "#remote_image_url" do
@@ -354,6 +361,13 @@ def default_url
354
361
355
362
expect ( @instance . image . current_path ) . to match ( /portrait.jpg$/ )
356
363
end
364
+
365
+ it "does not clear a previously stored file when an empty string is assigned" do
366
+ @instance . remote_image_url = "http://www.example.com/test.jpg"
367
+ @instance . image . store!
368
+ @instance . remote_image_url = ""
369
+ expect ( @instance . image . current_path ) . to match ( /test.jpg$/ )
370
+ end
357
371
end
358
372
359
373
describe '#store_image!' do
You can’t perform that action at this time.
0 commit comments