FlowAssertions.Ecto.SchemaA (Ecto Flow Assertions v0.1.0) View Source

Assertions for values defined by the macros in Ecto.Schema.

Link to this section Summary

Functions

Assert that an association has been loaded.

Map comparison that auto-ignores fields typically irrelevant when working with schemas.

Check that the given value matches a schema's name.

Fail when an association has been loaded.

Link to this section Functions

Link to this function

assert_assoc_loaded(struct, key_or_keys)

View Source

Assert that an association has been loaded.

Animal.typical(id, preload: [:service_gaps])
|> assert_loaded(:service_gaps)

The second argument can either be a single key or a list of keys.

Link to this function

assert_same_schema(new, old, opts \\ [])

View Source

Map comparison that auto-ignores fields typically irrelevant when working with schemas.

Works just like FlowAssertions.MapA.assert_same_map/3, except that it ignores the :updated_at, :created_at, and :__meta__ fields (if present).

old
|> VM.Animal.change(name: "bossie")
|> assert_same_schema(old, except: [name: "bossie"]

You can compare one or more of those three fields by using the comparing: or except: options:

assert_same_schema(new, old, except: newer_than(old)
Link to this function

assert_schema_name(value, name)

View Source

Check that the given value matches a schema's name.

We consider a schema's name to be that found inside its Ecto.Schema.Metadata, which is - by default - the module it was defined in. Embedded schemas don't have metadata, so FlowAssertions.StructA.assert_struct_named/2 is the appropriate assertion for them.

Link to this function

refute_assoc_loaded(struct, key_or_keys)

View Source

Fail when an association has been loaded.

Animal.typical(id, preload: [:species])
|> refute_loaded(:service_gaps)

The second argument can either be a single key or a list of keys.