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

Avoid purging attached blob when replacing it with itself

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