class ActiveStorage::Blob::PurgeableTest

Overview

A leak is a count, so the counts are what these assert: the rows of the three tables and the objects under the service root, before and after a purge. :nodoc:

Defined in:

active_storage/blob/purgeable_test.cr

Constant Summary

AVATAR_PATH = (Path["/woodpecker/src/codeberg.org/miry/marten-rails-bridge/src/active_storage/blob"].join("../../../examples/demo/src/assets/images/avatar.jpg")).normalize.to_s

The 1600x1200 image the demo serves, committed next to it.

BLOB_KEY = "gz0zdzhk0yn6zjhxfzl6qt1ys5rj"
CONTENT = "0123456789abcdef"

Instance Method Summary

Instance Method Detail

def setup #

def teardown #

def test_delete_files_removes_the_objects_and_leaves_the_row #

def test_purge_asks_for_no_prefix_when_the_blob_is_not_an_image #

Rails guards the prefix removal with image?, so a service is never asked to list a prefix no variant can be stored under. On S3 that guard is one request.


def test_purge_clears_the_prefix_of_this_blob_only #

A wrong prefix would take the objects of every other key sharded next to it, because variants/ reads as va/ri for all of them.


def test_purge_leaves_no_row_and_no_object_behind #

The leak this exists for, in the shape it was measured: a blob with two tracked variants and the derived-key object of a third, where only the original used to go.


def test_purge_refuses_a_blob_that_is_still_attached #

Rails refuses too, through a before_destroy guard, but swallows the error so the caller is told nothing. Here the refusal is the return value.


def test_purge_refuses_before_it_removes_any_variant #

def test_purge_removes_a_variant_image_although_it_is_attached #

The variant image blobs are attached, to their variant record. The guard must not see them, or a purge would stop at the first variant it reached.


def test_purge_removes_every_image_attached_to_a_variant_record #

A request that loses the race in ActiveStorage::VariantWithRecord#process attaches a second image to the same record, which VariantRecord#image never reads. It still has to go.


def test_purge_removes_nothing_for_a_blob_that_was_never_saved #

def test_purge_removes_the_derived_key_object #

def test_purge_removes_the_row_and_the_object_of_a_blob_with_no_variant #

def test_purge_removes_the_variant_image_blob_with_the_row_holding_it #

def test_purge_twice_does_not_raise #