Hoare.Store.Memory (hoare v0.2.0)

Copy Markdown View Source

A Hoare.Store that keeps records in the calling process, for testing a transition without a datastore.

invoice = Memory.put(%Invoice{id: 1, status: :issued, lines: [line]})
{:ok, _ctx} = Pay.run(%Pay{record: invoice}, &{:ok, &1}, store: Memory)
Memory.get(Invoice, 1).status
#=> :paid

Records live in the process dictionary, so async tests do not share them. The lock is not taken and preloads are ignored: seed a record as loaded as the states need it. update/1 takes what the schema's changeset/2 returned: anything shaped like an Ecto.Changeset (data, changes, valid?) or a {record, attrs} pair.

Summary

Functions

delete(schema, id)

@spec delete(module(), term()) :: :ok

get(schema, id)

@spec get(module(), term()) :: Hoare.Store.subject() | nil

put(record)