Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marick/ecto_test_data_builder
Use this code to build your own Elixir module that helps build Ecto test data.
https://github.com/marick/ecto_test_data_builder
Last synced: about 2 months ago
JSON representation
Use this code to build your own Elixir module that helps build Ecto test data.
- Host: GitHub
- URL: https://github.com/marick/ecto_test_data_builder
- Owner: marick
- Created: 2020-09-06T20:58:31.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-09-10T21:03:07.000Z (over 4 years ago)
- Last Synced: 2024-11-16T21:15:49.988Z (2 months ago)
- Language: Elixir
- Size: 101 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# README
This provides support code for writing Ecto test data builders that
are used like this:```elixir
repo =
empty_repo()
|> procedure("haltering", frequency: "twice per week")
|> reservation_for(["bossie"], ["haltering"], date: @wed)
|> reservation_for(["bossie"], ["haltering"], date: @mon)
```That code constructs test data for a database
configuration like this:I claim that code is a better way to set up test data than other approaches.
In addition to creating rows in database tables, the functions produce
a "repo cache", conventionally bound to `repo`, that contains a view into
the database that makes common testing operations simpler.For example, it's straightforward to have the `repo` structure contain
top-level fields that point directly to important values. This allows
you to avoid the busywork of keeping track of database ids. Instead,
there's only one "source of truth" and you use that:```elixir
# setuprepo =
...
|> animal("bossie", ...)
...# The function under test
... VM.Animal.fetch(:one_for_edit, repo.bossie.id) ...
^^^^^^^^^^^^^^
```That's surprisingly useful.
## More information
[Online documentation](https://hexdocs.pm/ecto_test_data_builder)
See [USE.md](./USE.md) for a description of using this package to
create a custom test-data builder.## Installation
Add `ecto_test_data_builder` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ecto_test_data_builder, "~> 0.1.0"}
]
end
```