Skip to content

Commit

Permalink
Replace File.exists? with File.exist?
Browse files Browse the repository at this point in the history
  • Loading branch information
kimyu92 committed May 2, 2023
1 parent 93e1739 commit e6beed9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion lib/carrierwave/sanitized_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
68 changes: 34 additions & 34 deletions spec/orm/activerecord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
10 changes: 5 additions & 5 deletions spec/sanitized_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions spec/uploader/store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions spec/uploader/versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,35 +376,35 @@ 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
@uploader_class.version(:mini)
@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
Expand Down

0 comments on commit e6beed9

Please sign in to comment.