class ActiveStorage::VariantWithRecordProcessedTest

Overview

The write path: a variation nothing has tracked is transformed, stored as a blob of its own and linked by a variant record, which is the layout a Rails app with config.active_storage.track_variants on writes. :nodoc:

Defined in:

active_storage/variant_with_record_test.cr

Constant Summary

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

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

BLOB_KEY = "gz0zdzhk0yn6zjhxfzl6qt1ys5rj"

Instance Method Summary

Instance Method Detail

def setup #

def teardown #

def test_processed_attaches_its_image_to_a_record_that_has_none #

A record written without its image, which #processed? reports as unprocessed. The record is reused and the transformed image is attached to it.


def test_processed_attaches_its_image_to_a_symbolized_record_that_has_none #

Same record, written by a Rails app from a spec where format: :jpg is a Symbol, so it carries the symbolized candidate. Inserting under the arrival digest instead would leave two rows for one variation, and the app, which looks only under its own digest, would keep re-processing the imageless row it can still see.


def test_processed_attaches_its_image_to_the_winner_record #

The winner inserted its record but has not attached its image yet, so this request's image is what the record gets.


def test_processed_discards_its_image_when_the_winner_has_one #

The loser of the race has already uploaded when it finds out. Its image is unreachable, so the row and the object both go.


def test_processed_does_not_process_a_single_candidate_variation_again #

Transformations carrying no string value offer a single candidate, so the write and the lookup cannot be told apart by which one they picked.


def test_processed_does_not_process_again #

def test_processed_does_not_process_what_another_request_tracked #

The second request of a cold variation: a new instance reads the record the first one wrote.

"jpg" gives this variation two digest candidates, so the request is written down under one fingerprint and looked up under two. The second request must still find the record rather than transform and upload a second image.


def test_processed_names_the_image_after_the_source_blob #

def test_processed_raises_when_the_insert_fails_for_another_reason #

The rescue around the insert cannot name the unique violation, so it has to rescue everything. A failure the re-read does not explain must still reach the caller: an unsaved source blob has no id, which the record rejects, and no row appears to blame it on.


def test_processed_raises_when_the_source_is_not_stored #

def test_processed_records_the_decoded_variation_digest #

The digest of the transformations as they arrived, which is the first #digest_candidates entry and the one Rails' own controller looks up after decoding a URL key. The symbolized candidate is not written: no request can arrive in that form.


def test_processed_replaces_the_memoized_miss #

#record and #image memoize a miss, so #processed has to replace what it cached or every reader keeps seeing the variation as unprocessed.


def test_processed_resizes_the_source #

The dimensions come from the bytes that were stored, not from the variation that asked for them.


def test_processed_returns_itself #

def test_processed_writes_the_record_the_image_blob_and_the_attachment #