From 0e2c3df24900eaf195e69bc1dfa5801d6911e976 Mon Sep 17 00:00:00 2001 From: Kellen Presley Date: Thu, 14 Dec 2023 12:43:38 -0800 Subject: [PATCH 1/2] bump version of database cleaner --- active_storage-postgresql.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_storage-postgresql.gemspec b/active_storage-postgresql.gemspec index b1ae87c..792298a 100644 --- a/active_storage-postgresql.gemspec +++ b/active_storage-postgresql.gemspec @@ -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 From 10ac91036b8705cf5ed35bc07e6472a2c1923a50 Mon Sep 17 00:00:00 2001 From: Kellen Presley Date: Thu, 14 Dec 2023 12:44:05 -0800 Subject: [PATCH 2/2] check if file actually exists --- lib/active_storage/postgresql/file.rb | 2 +- test/active_storage/shared_service_tests.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/active_storage/postgresql/file.rb b/lib/active_storage/postgresql/file.rb index 860c0e5..5fb3a91 100644 --- a/lib/active_storage/postgresql/file.rb +++ b/lib/active_storage/postgresql/file.rb @@ -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| diff --git a/test/active_storage/shared_service_tests.rb b/test/active_storage/shared_service_tests.rb index bdbc625..5a14582 100644 --- a/test/active_storage/shared_service_tests.rb +++ b/test/active_storage/shared_service_tests.rb @@ -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)