View Source SchemaAssertions (Schema Assertions v0.2.0)

ExUnit assertions for Ecto schemas.

examples

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

Link to this section Summary

Functions

Asserts that the given schema module has a belongs_to association.

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

Asserts that the given schema module has a has_one association.

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

Link to this section Functions

Link to this function

assert_belongs_to(schema_module, association, association_module)

View Source

Specs

assert_belongs_to(module(), atom(), module()) :: true

Asserts that the given schema module has a belongs_to association.

example

Example

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

assert_fields(schema_module, fields)

View Source
Link to this function

assert_has_many(schema_module, association, association_module_or_opts)

View Source

Specs

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

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
Link to this function

assert_has_one(schema_module, association, association_module)

View Source

Specs

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

Asserts that the given schema module has a has_one association.

example

Example

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

assert_is_ecto_schema(schema_module)

View Source
Link to this function

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

View Source

Specs

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

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

Link to this function

assert_schema_module_exists(schema_module)

View Source
Link to this function

assert_schema_table_exists(table_name)

View Source
Link to this function

assert_schema_table_name(schema_module, expected_table_name)

View Source