From e6beed9b2f96ef96f4fc55d2d4ec676dd4bcf9af Mon Sep 17 00:00:00 2001 From: Kim Yu Ng Date: Tue, 2 May 2023 15:45:05 -0500 Subject: [PATCH] Replace File.exists? with File.exist? --- lib/carrierwave/sanitized_file.rb | 2 +- spec/orm/activerecord_spec.rb | 68 +++++++++++++++---------------- spec/sanitized_file_spec.rb | 10 ++--- spec/uploader/store_spec.rb | 8 ++-- spec/uploader/versions_spec.rb | 24 +++++------ 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/lib/carrierwave/sanitized_file.rb b/lib/carrierwave/sanitized_file.rb index 52013bc53..6d039e6fa 100644 --- a/lib/carrierwave/sanitized_file.rb +++ b/lib/carrierwave/sanitized_file.rb @@ -291,7 +291,7 @@ def file=(file) def mkdir!(path, directory_permissions) options = {} options[:mode] = directory_permissions if directory_permissions - FileUtils.mkdir_p(File.dirname(path), **options) unless File.exists?(File.dirname(path)) + FileUtils.mkdir_p(File.dirname(path), **options) unless File.exist?(File.dirname(path)) end def chmod!(path, permissions) diff --git a/spec/orm/activerecord_spec.rb b/spec/orm/activerecord_spec.rb index 41f10b227..ff332298c 100644 --- a/spec/orm/activerecord_spec.rb +++ b/spec/orm/activerecord_spec.rb @@ -622,7 +622,7 @@ def filename @event = @class.new @event.image = stub_file('old.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end after do @@ -633,29 +633,29 @@ def filename it "should remove old file if old file had a different path" do @event.image = stub_file('new.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_false end it "should not remove old file if old file had a different path but config is false" do @uploader.stub!(:remove_previously_stored_files_after_update).and_return(false) @event.image = stub_file('new.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end it "should not remove file if old file had the same path" do @event.image = stub_file('old.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end it "should not remove file if validations fail on save" do @class.validate { |r| r.errors.add :textfile, "FAIL!" } @event.image = stub_file('new.jpeg') expect(@event.save).to be_false - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end end @@ -670,22 +670,22 @@ def filename @event.image = stub_file('old.jpeg') @event.foo = 'test' expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/test.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/test.jpeg'))).to be_true expect(@event.image.read).to eq('this is stuff') end it "should not remove file if old file had the same dynamic path" do @event.image = stub_file('test.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/test.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/test.jpeg'))).to be_true end it "should remove old file if old file had a different dynamic path" do @event.foo = "new" @event.image = stub_file('test.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/test.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/test.jpeg'))).to be_false end end end @@ -704,8 +704,8 @@ def filename @event = @class.new @event.image = stub_file('old.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/thumb_old.jpeg'))).to be_true end after do @@ -715,17 +715,17 @@ def filename it "should remove old file if old file had a different path" do @event.image = stub_file('new.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/thumb_new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_false - expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/thumb_new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/thumb_old.jpeg'))).to be_false end it "should not remove file if old file had the same path" do @event.image = stub_file('old.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/thumb_old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/thumb_old.jpeg'))).to be_true end end @@ -745,8 +745,8 @@ def filename @event.image = stub_file('old.jpeg') @event.textfile = stub_file('old.txt') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.txt'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.txt'))).to be_true end after do @@ -757,27 +757,27 @@ def filename @event.image = stub_file('new.jpeg') @event.textfile = stub_file('new.txt') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_false - expect(File.exists?(public_path('uploads/new.txt'))).to be_true - expect(File.exists?(public_path('uploads/old.txt'))).to be_false + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/new.txt'))).to be_true + expect(File.exist?(public_path('uploads/old.txt'))).to be_false end it "should remove old file1 but not file2 if old file1 had a different path but old file2 has the same path" do @event.image = stub_file('new.jpeg') @event.textfile = stub_file('old.txt') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_false - expect(File.exists?(public_path('uploads/old.txt'))).to be_true + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/old.txt'))).to be_true end it "should not remove file1 or file2 if file1 and file2 have the same paths" do @event.image = stub_file('old.jpeg') @event.textfile = stub_file('old.txt') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.txt'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.txt'))).to be_true end end @@ -794,7 +794,7 @@ def filename @event = @class.new @event.avatar = stub_file('old.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end after do @@ -804,14 +804,14 @@ def filename it "should remove old file if old file had a different path" do @event.avatar = stub_file('new.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/new.jpeg'))).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_false + expect(File.exist?(public_path('uploads/new.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_false end it "should not remove file if old file had the same path" do @event.avatar = stub_file('old.jpeg') expect(@event.save).to be_true - expect(File.exists?(public_path('uploads/old.jpeg'))).to be_true + expect(File.exist?(public_path('uploads/old.jpeg'))).to be_true end end end diff --git a/spec/sanitized_file_spec.rb b/spec/sanitized_file_spec.rb index eb3a920e9..e116141d6 100644 --- a/spec/sanitized_file_spec.rb +++ b/spec/sanitized_file_spec.rb @@ -10,7 +10,7 @@ end after(:all) do - if File.exists?(file_path('llama.jpg')) + if File.exist?(file_path('llama.jpg')) FileUtils.rm(file_path('llama.jpg')) end FileUtils.rm_rf(public_path) @@ -286,7 +286,7 @@ it "should be moved to the correct location" do @sanitized_file.move_to(file_path('gurr.png')) - File.exists?( file_path('gurr.png') ).should be_true + File.exist?( file_path('gurr.png') ).should be_true end it "should have changed its path when moved" do @@ -335,7 +335,7 @@ it "should be copied to the correct location" do @sanitized_file.copy_to(file_path('gurr.png')) - File.exists?( file_path('gurr.png') ).should be_true + File.exist?( file_path('gurr.png') ).should be_true file_path('gurr.png').should be_identical_to(file_path('llama.jpg')) end @@ -429,9 +429,9 @@ describe '#delete' do it "should remove it from the filesystem" do - File.exists?(@sanitized_file.path).should be_true + File.exist?(@sanitized_file.path).should be_true @sanitized_file.delete - File.exists?(@sanitized_file.path).should be_false + File.exist?(@sanitized_file.path).should be_false end end diff --git a/spec/uploader/store_spec.rb b/spec/uploader/store_spec.rb index 807621882..379c489a0 100644 --- a/spec/uploader/store_spec.rb +++ b/spec/uploader/store_spec.rb @@ -348,13 +348,13 @@ def filename @stored_path = ::File.expand_path(@uploader.store_path, @uploader.root) @cached_path.should == public_path('uploads/tmp/1369894322-345-2255/test.jpg') - File.exists?(@cached_path).should be_true - File.exists?(@stored_path).should be_false + File.exist?(@cached_path).should be_true + File.exist?(@stored_path).should be_false @uploader.store! - File.exists?(@cached_path).should be_false - File.exists?(@stored_path).should be_true + File.exist?(@cached_path).should be_false + File.exist?(@stored_path).should be_true end it "should use move_to() during store!()" do diff --git a/spec/uploader/versions_spec.rb b/spec/uploader/versions_spec.rb index db14a037c..f3f222074 100644 --- a/spec/uploader/versions_spec.rb +++ b/spec/uploader/versions_spec.rb @@ -376,13 +376,13 @@ def move_to_cache it "should recreate all versions if any are missing" do @uploader.store!(@file) - File.exists?(@uploader.thumb.path).should == true + File.exist?(@uploader.thumb.path).should == true FileUtils.rm(@uploader.thumb.path) - File.exists?(@uploader.thumb.path).should == false + File.exist?(@uploader.thumb.path).should == false @uploader.recreate_versions! - File.exists?(@uploader.thumb.path).should == true + File.exist?(@uploader.thumb.path).should == true end it "should recreate only specified versions if passed as args" do @@ -390,21 +390,21 @@ def move_to_cache @uploader_class.version(:maxi) @uploader.store!(@file) - File.exists?(@uploader.thumb.path).should == true - File.exists?(@uploader.mini.path).should == true - File.exists?(@uploader.maxi.path).should == true + File.exist?(@uploader.thumb.path).should == true + File.exist?(@uploader.mini.path).should == true + File.exist?(@uploader.maxi.path).should == true FileUtils.rm(@uploader.thumb.path) - File.exists?(@uploader.thumb.path).should == false + File.exist?(@uploader.thumb.path).should == false FileUtils.rm(@uploader.mini.path) - File.exists?(@uploader.mini.path).should == false + File.exist?(@uploader.mini.path).should == false FileUtils.rm(@uploader.maxi.path) - File.exists?(@uploader.maxi.path).should == false + File.exist?(@uploader.maxi.path).should == false @uploader.recreate_versions!(:thumb, :maxi) - File.exists?(@uploader.thumb.path).should == true - File.exists?(@uploader.maxi.path).should == true - File.exists?(@uploader.mini.path).should == false + File.exist?(@uploader.thumb.path).should == true + File.exist?(@uploader.maxi.path).should == true + File.exist?(@uploader.mini.path).should == false end it "should not create version if proc returns false" do