aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/test')
-rw-r--r--activestorage/test/models/attachments_test.rb14
-rw-r--r--activestorage/test/test_helper.rb1
2 files changed, 15 insertions, 0 deletions
diff --git a/activestorage/test/models/attachments_test.rb b/activestorage/test/models/attachments_test.rb
index cb52a57b33..a5fcad1bab 100644
--- a/activestorage/test/models/attachments_test.rb
+++ b/activestorage/test/models/attachments_test.rb
@@ -80,6 +80,20 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
end
end
+ test "replace independent attached blob" do
+ @user.cover_photo.attach create_blob(filename: "funky.jpg")
+
+ perform_enqueued_jobs do
+ assert_difference -> { ActiveStorage::Blob.count }, +1 do
+ assert_no_difference -> { ActiveStorage::Attachment.count } do
+ @user.cover_photo.attach create_blob(filename: "town.jpg")
+ end
+ end
+ end
+
+ assert_equal "town.jpg", @user.cover_photo.filename.to_s
+ end
+
test "attach blob to new record" do
user = User.new(name: "Jason")
diff --git a/activestorage/test/test_helper.rb b/activestorage/test/test_helper.rb
index aaf1d452ea..9b5cd41335 100644
--- a/activestorage/test/test_helper.rb
+++ b/activestorage/test/test_helper.rb
@@ -65,5 +65,6 @@ ActiveRecord::Base.send :include, GlobalID::Identification
class User < ActiveRecord::Base
has_one_attached :avatar
+ has_one_attached :cover_photo, dependent: false
has_many_attached :highlights
end