Tack.Credo.Check.TimestampRewriteInTest (pica v0.1.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

A test that needs an old row moves its stamp with the suite's backdate/3 helper (test/support/backdate.ex), not an update_all.

elixir-code-review, references/test-quality.md:

Age a row with backdate/3, never a local update_all. A test that places a row in time calls backdate/3: {amount, unit} always means "that long ago", the instant is truncated to the column's precision, and a query matching no rows fails.

Left alone, a suite grows one backdate helper per file, with incompatible signatures: some add the offset and are called with a negative number, some subtract it; half truncate and half do not; some return silently when nothing matched, so a test that backdated no row asserts against fresh stamps and passes. Each new test copies whichever sits nearest.

This flags any update_all whose set: names a literal *_at key — the way every timestamp column is named. A domain-named wrapper (joined_at/2, move_expiry/2) is fine as long as its body calls backdate/3, which writes its keys dynamically and so is never flagged itself. Scope the check to test/ in .credo.exs; lib/ writes updated_at in bulk on purpose.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.