Skip to content

Commit

Permalink
Fix test/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Oct 18, 2021
1 parent 8a91c0b commit fa680ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/valkyrie/specs/shared_specs/storage_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ class Valkyrie::Specs::CustomResource < Valkyrie::Resource
expect(uploaded_file.valid?(digests: { sha1: sha1 })).to be true
end

it "doesn't open a file handle on discovery" do
it "doesn't leave a file handle open on upload/find_by" do
# No file handle left open from upload.
resource = Valkyrie::Specs::CustomResource.new(id: "testdiscovery")
pre_open_files = open_files
uploaded_file = storage_adapter.upload(file: file, original_filename: 'foo.jpg', resource: resource, fake_upload_argument: true)
file.close
expect(pre_open_files.size).to eq open_files.size

# No file handle left open from find_by
pre_open_files = open_files
the_file = storage_adapter.find_by(id: uploaded_file.id)
expect(the_file).to be_kind_of Valkyrie::StorageAdapter::File
# the_file.io
expect(pre_open_files.size).to eq open_files.size
end

Expand Down
6 changes: 3 additions & 3 deletions lib/valkyrie/storage/disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def find_by(id:)
raise Valkyrie::StorageAdapter::FileNotFound
end

## Lazy file takes open parameters but doesn't open up a file handle. This
# way StorageAdapter#find_by doesn't open a handle silently and never clean
# up after itself.
## LazyFile takes File.open parameters but doesn't leave a file handle open on
# instantiation. This way StorageAdapter#find_by doesn't open a handle
# silently and never clean up after itself.
class LazyFile
def self.open(path, mode)
# Open the file regularly and close it, so it can error if it doesn't
Expand Down

0 comments on commit fa680ac

Please sign in to comment.