{"id":16732533,"url":"https://github.com/martinthenth/factoid","last_synced_at":"2025-12-11T23:49:38.722Z","repository":{"id":172348108,"uuid":"621548942","full_name":"martinthenth/factoid","owner":"martinthenth","description":"A test fixtures library - based on Ecto","archived":false,"fork":false,"pushed_at":"2024-06-23T08:35:09.000Z","size":41,"stargazers_count":3,"open_issues_count":6,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-17T03:44:16.048Z","etag":null,"topics":["ecto","elixir","exunit","phoenix","testing"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/factoid","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martinthenth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-30T22:21:53.000Z","updated_at":"2024-06-22T11:17:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"1a3adeac-511b-452f-b1ac-c7f10dba138f","html_url":"https://github.com/martinthenth/factoid","commit_stats":null,"previous_names":["martinthenth/fact","recruiterbay/fact","recruiterbay/factoid"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinthenth%2Ffactoid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinthenth%2Ffactoid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinthenth%2Ffactoid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinthenth%2Ffactoid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinthenth","download_url":"https://codeload.github.com/martinthenth/factoid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874189,"owners_count":20524576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecto","elixir","exunit","phoenix","testing"],"created_at":"2024-10-12T23:45:26.485Z","updated_at":"2025-12-11T23:49:38.689Z","avatar_url":"https://github.com/martinthenth.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Factoid\n\nDocumentation for `Factoid`.\n\nFactoid is a library for generating test data using factories build on Ecto.Schemas.\n\nIt's similar to [ExMachina](https://github.com/thoughtbot/ex_machina) but it is not a drop-in\nreplacement. Where ExMachina builds and keeps associations in the returned records, Factoid drops\nthe associations and keeps the associated `id` fields. This opinionated approach helps building\nsimpler tests.\n\n## Installation\n\nAdd `factoid` to the list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:factoid, \"~\u003e 0.1\"}]\nend\n```\n\n## Usage\n\nDefine a factory module that uses the `Factoid` behaviour, select the repo module, and define\n`build/2` functions for each factory.\n\n```elixir\ndef App.Factory do\n  @behaviour Factoid\n\n  use Factoid, repo: App.Repo\n\n  alias App.Schemas.User\n  alias App.Schemas.UserAvatar\n\n  @impl Factoid\n  def build(factory, attrs \\\\ %{})\n\n  def build(:user, attrs) do\n    %User{\n      first_name: \"Jane\",\n      last_name: \"Doe\",\n      email_address: \"jane-#{unique_integer()}@example.com\",\n    }\n    |\u003e Map.merge(attrs)\n  end\n\n  def build(:user_avatar, attrs) do\n    %UserAvatar{\n      user: build(:user)\n    }\n    |\u003e Map.merge(attrs)\n  end\nend\n```\n\nIn your tests you can import your factory and use it to create test data.\n\n```elixir\ndef App.ModuleTest do\n  use DataCase\n\n  import App.Factory\n\n  alias App.Repo\n  alias App.Schemas.User\n\n  test \"creates a user\" do\n    user_1 = insert(:user)\n    user_2 = insert(:user, name: \"John\")\n\n    assert user_1 != user_2\n    assert user_1 == Repo.get(User, user_1.id)\n    assert user_2.name == \"John\"\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinthenth%2Ffactoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinthenth%2Ffactoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinthenth%2Ffactoid/lists"}