diff options
author | George Claghorn <george@basecamp.com> | 2018-07-16 15:57:43 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-07-16 15:57:43 -0400 |
commit | 36ec5428bfe78831e4c5c001bd8e7ce45c238b33 (patch) | |
tree | 4fcdf44f8dd90aac4d926da99be2f5a0b3e5ceba /activestorage/test | |
parent | 1d13de4e39aa8045d1829ebbec5f7a8a192ed4b2 (diff) | |
download | rails-36ec5428bfe78831e4c5c001bd8e7ce45c238b33.tar.gz rails-36ec5428bfe78831e4c5c001bd8e7ce45c238b33.tar.bz2 rails-36ec5428bfe78831e4c5c001bd8e7ce45c238b33.zip |
Fix that successive ActiveStorage::Attached::Many#attach calls would overwrite previous attachments
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/attached/many_test.rb | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/activestorage/test/models/attached/many_test.rb b/activestorage/test/models/attached/many_test.rb index 2a45829da8..61a80b5dda 100644 --- a/activestorage/test/models/attached/many_test.rb +++ b/activestorage/test/models/attached/many_test.rb @@ -106,6 +106,17 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase assert_equal "video.mp4", @user.highlights.second.filename.to_s end + test "attaching existing records to an existing blob one at a time" do + @user.highlights.attach create_blob(filename: "funky.jpg") + @user.highlights.attach create_blob(filename: "town.jpg") + assert_equal "funky.jpg", @user.highlights.first.filename.to_s + assert_equal "town.jpg", @user.highlights.second.filename.to_s + + @user.reload + assert_equal "funky.jpg", @user.highlights.first.filename.to_s + assert_equal "town.jpg", @user.highlights.second.filename.to_s + end + test "updating an existing record to attach existing blobs" do @user.update! highlights: [ create_file_blob(filename: "racecar.jpg"), create_file_blob(filename: "video.mp4") ] assert_equal "racecar.jpg", @user.highlights.first.filename.to_s @@ -195,32 +206,6 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase end end - test "removing dependent attachments from an existing record" do - [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs| - @user.highlights.attach blobs - - assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blobs.first ] do - assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blobs.second ] do - @user.highlights.attach [] - end - end - - assert_not @user.highlights.attached? - end - end - - test "removing independent attachments from an existing record" do - [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs| - @user.vlogs.attach blobs - - assert_no_enqueued_jobs only: ActiveStorage::PurgeJob do - @user.vlogs.attach [] - end - - assert_not @user.vlogs.attached? - end - end - test "updating an existing record to remove dependent attachments" do [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs| @user.highlights.attach blobs |