SchemaAssertions (Schema Assertions v2.1.0)

View Source

ExUnit assertions for Ecto schemas.

Examples

iex> import SchemaAssertions
iex> alias SchemaAssertions.Test.Schema
...>
iex> assert_schema Schema.House, "houses",
...>     address: :text,
...>     id: :bigserial
...>
iex> assert_schema Schema.House, "houses",
...>     address: :text,
...>     id: :id

Summary

Functions

assert_belongs_to(schema_module, association, association_module, opts \\ [])

@spec assert_belongs_to(
  module(),
  atom(),
  module(),
  opts :: SchemaAssertions.Schema.belongs_to_opts()
) ::
  true

Asserts that the given schema module has a belongs_to association.

Example

iex> alias SchemaAssertions.Test.Schema
iex> SchemaAssertions.assert_belongs_to(Schema.Room, :house, Schema.House)
true

iex> alias SchemaAssertions.Test.Schema
iex> SchemaAssertions.assert_belongs_to(Schema.Pet, :home, Schema.House, source: :house_id)
true

assert_enum(name, values)

assert_fields(schema_module, fields)

assert_has_many(schema_module, association, association_module_or_opts)

@spec assert_has_many(module(), atom(), module() | Keyword.t()) :: true

Asserts that the given schema module has a has_many or has_many :through association.

Example

iex> alias SchemaAssertions.Test.Schema
iex> SchemaAssertions.assert_has_many(Schema.House, :rooms, Schema.Room)
true

iex> alias SchemaAssertions.Test.Schema
iex> SchemaAssertions.assert_has_many(Schema.House, :windows, through: [:rooms, :windows])
true

assert_has_one(schema_module, association, association_module_or_opts)

@spec assert_has_one(module(), atom(), module()) :: true | no_return()

Asserts that the given schema module has a has_one association.

Example

iex> alias SchemaAssertions.Test.Schema
iex> SchemaAssertions.assert_has_one(Schema.House, :foundation, Schema.Foundation)
true

assert_is_ecto_schema(schema_module)

assert_schema(schema_module, table_name, fields \\ [])

@spec assert_schema(module(), binary(), Keyword.t()) :: true | no_return()

Asserts that the given schema module exists and that its corresponding database table exists.

assert_schema_module_exists(schema_module)

assert_schema_table_exists(table_name)

assert_schema_table_name(schema_module, expected_table_name)