Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug related to trying to call lo_import on tempfiles that haven't been persisted #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion active_storage-postgresql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Gem::Specification.new do |s|
"!= 1.4.0", "!= 1.4.1", "!= 1.4.2", "!= 1.4.3", "!= 1.4.4", "!= 1.4.5"

s.add_development_dependency "pry", "~> 0.11"
s.add_development_dependency "database_cleaner", "~> 1.7"
s.add_development_dependency "database_cleaner", "~> 2.0"
s.add_development_dependency "appraisal"
end
2 changes: 1 addition & 1 deletion lib/active_storage/postgresql/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def digest
before_create :verify_checksum, if: :checksum

def write_or_import
if io.respond_to?(:to_path)
if io.respond_to?(:to_path) && File.exist?(io.to_path)
import(io.to_path)
else
open(::PG::INV_WRITE) do |file|
Expand Down
19 changes: 19 additions & 0 deletions test/active_storage/shared_service_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ module ActiveStorage::Service::SharedServiceTests
end
end

test "uploading a non-persisted (but still readable) file" do
begin
key = SecureRandom.base58(24)
data = "Something else entirely!"
file = Tempfile.open("upload")
file.write(data)
file.rewind
file.delete

assert !File.exist?(file.to_path)

@service.upload(key, file, checksum: Digest::MD5.base64digest(data))

assert_equal data, @service.download(key)
ensure
@service.delete key
end
end

test "uploading without integrity" do
begin
key = SecureRandom.base58(24)
Expand Down