View Source DeltaCheck (DeltaCheck v0.1.1)
Main API for DeltaCheck, a testing toolkit for making assertions on database writes.
Link to this section Summary
Functions
Tracks database writes made in the given block, and asserts that the resulting delta matches the given pattern.
Tracks database writes made in the given block, and asserts that no writes were made.
Compares two snapshots and returns a delta.
Returns the name of the primary key of the schema.
Returns all Ecto schemas for the given application.
Returns a snapshot of the database.
Tracks database writes made in the given function, and returns a tuple with the containing the return value of the function and a database delta.
Link to this section Types
@type delta() :: [ insert: Ecto.Schema.t(), update: {Ecto.Schema.t(), [{atom(), term()}]}, delete: Ecto.Schema.t() ]
@type snapshot() :: %{optional(module()) => %{optional(term()) => Ecto.Schema.t()}}
Link to this section Functions
Tracks database writes made in the given block, and asserts that the resulting delta matches the given pattern.
options
Options
:schemas
- A list of schemas to track writes for, instead of the default schemas provided in the application configuration.
examples
Examples
iex> assert_changes(insert: %User{name: "John Doe"}) do
iex> Accounts.create_user(%{name: "John Doe"})
iex> end
Tracks database writes made in the given block, and asserts that no writes were made.
options
Options
:schemas
- A list of schemas to track writes for, instead of the default schemas provided in the application configuration.
examples
Examples
iex> assert_no_changes do
iex> Accounts.create_user(%{name: nil})
iex> end
Compares two snapshots and returns a delta.
examples
Examples
iex> compare(
iex> %{User => %{1 => %User{id: 1, name: "John Doe"}}},
iex> %{User => %{1 => %User{id: 1, name: "Jane Doe"}}}
iex> )
[update: {%User{id: 1, name: "Jane Doe"}, name: {"John Doe", "Jane Doe"}}]
Returns the name of the primary key of the schema.
examples
Examples
iex> get_primary_key!(User)
:id
Returns all Ecto schemas for the given application.
examples
Examples
iex> get_schemas(:my_app)
[Foo, Bar, Baz]
Returns a snapshot of the database.
options
Options
:schemas
- A list of schemas to include in the snapshot, instead of the default schemas provided in the application configuration.
examples
Examples
iex> {:ok, %{id: id} = user} = Accounts.create_user(%{name: "John Doe"})
iex> snapshot(schemas: [User])
%{User => %{id => user}}
Tracks database writes made in the given function, and returns a tuple with the containing the return value of the function and a database delta.
options
Options
:schemas
- A list of schemas to track writes for, instead of the default schemas provided in the application configuration.
examples
Examples
iex> {{_, user}, _} = track_changes(fn ->
iex> Accounts.create_user(%{name: "John Doe"})
iex> end)
{{:ok, user}, [insert: user]}