diff options
author | George Claghorn <george@basecamp.com> | 2017-11-13 16:36:39 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2017-11-13 16:36:39 -0500 |
commit | 704a7e425ca99af1b778c764a86e5388647631dd (patch) | |
tree | 115382292c62a22a4ae2220b20f5dd94eba8ff70 /activestorage/test | |
parent | 233d6a2b563e34156c5fc2317c19dc1823447c18 (diff) | |
download | rails-704a7e425ca99af1b778c764a86e5388647631dd.tar.gz rails-704a7e425ca99af1b778c764a86e5388647631dd.tar.bz2 rails-704a7e425ca99af1b778c764a86e5388647631dd.zip |
Preserve existing metadata when analyzing a blob
Closes #31138.
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/attachments_test.rb | 25 | ||||
-rw-r--r-- | activestorage/test/test_helper.rb | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/activestorage/test/models/attachments_test.rb b/activestorage/test/models/attachments_test.rb index 47f2bd7911..96bc963cff 100644 --- a/activestorage/test/models/attachments_test.rb +++ b/activestorage/test/models/attachments_test.rb @@ -88,6 +88,16 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase end end + test "preserve existing metadata when analyzing a newly-attached blob" do + blob = create_file_blob(metadata: { foo: "bar" }) + + perform_enqueued_jobs do + @user.avatar.attach blob + end + + assert_equal "bar", blob.reload.metadata[:foo] + end + test "purge attached blob" do @user.avatar.attach create_blob(filename: "funky.jpg") avatar_key = @user.avatar.key @@ -193,6 +203,21 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase end end + test "preserve existing metadata when analyzing newly-attached blobs" do + blobs = [ + create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg", metadata: { foo: "bar" }), + create_file_blob(filename: "video.mp4", content_type: "video/mp4", metadata: { foo: "bar" }) + ] + + perform_enqueued_jobs do + @user.highlights.attach(blobs) + end + + blobs.each do |blob| + assert_equal "bar", blob.reload.metadata[:foo] + end + end + test "purge attached blobs" do @user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "wonky.jpg") highlight_keys = @user.highlights.collect(&:key) diff --git a/activestorage/test/test_helper.rb b/activestorage/test/test_helper.rb index 38408cdad3..55da781f2a 100644 --- a/activestorage/test/test_helper.rb +++ b/activestorage/test/test_helper.rb @@ -45,8 +45,8 @@ class ActiveSupport::TestCase ActiveStorage::Blob.create_after_upload! io: StringIO.new(data), filename: filename, content_type: content_type end - def create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg") - ActiveStorage::Blob.create_after_upload! io: file_fixture(filename).open, filename: filename, content_type: content_type + def create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg", metadata: nil) + ActiveStorage::Blob.create_after_upload! io: file_fixture(filename).open, filename: filename, content_type: content_type, metadata: metadata end def create_blob_before_direct_upload(filename: "hello.txt", byte_size:, checksum:, content_type: "text/plain") |