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 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)