提交 b06c28f5 编写于 作者: G George Claghorn

Avoid purging attached blob when replacing it with itself

上级 73980148
......@@ -64,12 +64,16 @@ def purge_later
private
def replace(attachable)
blob.tap do
unless attachable == blob
previous_blob = blob
transaction do
detach
write_attachment build_attachment_from(attachable)
end
end.purge_later
previous_blob.purge_later
end
end
def build_attachment_from(attachable)
......
......@@ -56,6 +56,18 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
assert ActiveStorage::Blob.service.exist?(@user.avatar.key)
end
test "replace attached blob with itself" do
@user.avatar.attach create_blob(filename: "funky.jpg")
assert_no_changes -> { @user.reload.avatar.blob } do
assert_no_changes -> { @user.reload.avatar.attachment } do
assert_no_enqueued_jobs do
@user.avatar.attach @user.avatar.blob
end
end
end
end
test "attach blob to new record" do
user = User.new(name: "Jason")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册