Fix broken background image after removal (#2817)
ActiveStorage::Record and ApplicationRecord used separate connection pools (from separate `connects_to` calls). This meant `belongs_to touch: true` on attachments silently failed — the card couldn't join the attachment's transaction to receive the deferred touch, so fragment caches were never invalidated after image removal. Fix by delegating `connection_pool` from ActiveStorage::Record to ApplicationRecord so they share a single pool.
This commit is contained in:
@@ -57,6 +57,32 @@ class Storage::NoReuseTest < ActiveSupport::TestCase
|
||||
).count
|
||||
end
|
||||
|
||||
test "purge touches the record to invalidate cache" do
|
||||
card = @board.cards.create!(title: "Card", creator: users(:david))
|
||||
card.image.attach(io: file_fixture("moon.jpg").open, filename: "moon.jpg", content_type: "image/jpeg")
|
||||
|
||||
original_updated_at = card.reload.updated_at
|
||||
|
||||
travel 1.second do
|
||||
card.image.purge
|
||||
end
|
||||
|
||||
assert card.reload.updated_at > original_updated_at
|
||||
end
|
||||
|
||||
test "purge_later touches the record to invalidate cache" do
|
||||
card = @board.cards.create!(title: "Card", creator: users(:david))
|
||||
card.image.attach(io: file_fixture("moon.jpg").open, filename: "moon.jpg", content_type: "image/jpeg")
|
||||
|
||||
original_updated_at = card.reload.updated_at
|
||||
|
||||
travel 1.second do
|
||||
card.image.purge_later
|
||||
end
|
||||
|
||||
assert card.reload.updated_at > original_updated_at
|
||||
end
|
||||
|
||||
test "purge_later does not purge blob when still attached elsewhere" do
|
||||
file = file_fixture("moon.jpg")
|
||||
blob = ActiveStorage::Blob.create_and_upload! \
|
||||
|
||||
Reference in New Issue
Block a user