From c5cf89f99d50c9b7806889ca110b5466f98f3a7f Mon Sep 17 00:00:00 2001 From: Potiguar Faga Catalan Date: Mon, 25 Jul 2022 15:51:20 -0300 Subject: [PATCH 01/25] Fix small syntax error in documentation (#421) Add missing comma --- lib/ex_machina/sequence.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ex_machina/sequence.ex b/lib/ex_machina/sequence.ex index 05a94ad..2268159 100644 --- a/lib/ex_machina/sequence.ex +++ b/lib/ex_machina/sequence.ex @@ -30,7 +30,7 @@ defmodule ExMachina.Sequence do ExMachina.Sequence.reset() - ExMachina.Sequence.next("alphabet_sequence"["A", "B"]) # resets so the return value is "A" + ExMachina.Sequence.next("alphabet_sequence", ["A", "B"]) # resets so the return value is "A" If you want to reset sequences at the beginning of every test, put it in a `setup` block in your test. From c89902e58849cecda7940541d2a66b9516ab6549 Mon Sep 17 00:00:00 2001 From: Doug March Date: Tue, 20 Sep 2022 11:44:38 -0400 Subject: [PATCH 02/25] Update README.md (#424) Move copy from `master` to `main` in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d194a7..9d9660a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ExMachina makes it easy to create test data and associations. It works great with Ecto, but is configurable to work with any persistence library. -> **This README follows master, which may not be the currently published version**. Here are the +> **This README follows the main branch, which may not be the currently published version**. Here are the [docs for the latest published version of ExMachina](https://hexdocs.pm/ex_machina/readme.html). ## Installation From 8e66321f8268cba2c4597b8bb445c1da2961e07c Mon Sep 17 00:00:00 2001 From: Conrad Schilbe Date: Wed, 26 Oct 2022 14:59:28 -0600 Subject: [PATCH 03/25] Preserve dates when using string_params_for. Added config so it is not a breaking change yet (#420) Resolves #362 https://github.com/thoughtbot/ex_machina/issues/362 This PR introduces a configuration option to preserve dates when using the string_params_for function, making it a non breaking change for now. Add the following to your config/test.exs file to enable this: `config :ex_machina, preserve_dates: true` --- config/config.exs | 9 +++++++++ config/test.exs | 2 ++ lib/ex_machina/ecto.ex | 8 ++++++++ priv/test_repo/migrations/1_migrate_all.exs | 1 + test/ex_machina/ecto_test.exs | 12 ++++++++++++ test/support/models/article.ex | 1 + 6 files changed, 33 insertions(+) diff --git a/config/config.exs b/config/config.exs index c91b69e..991d82a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -2,6 +2,15 @@ # and its dependencies with the aid of the Mix.Config module. use Mix.Config +# By default, ExMachina will convert datetime values to a map with string +# keys such as +# %{ "calendar" => Calendar.ISO, "day" => 4, "hour" => 17, "microsecond" => {657863, 6}, "minute" => 25, "month" => 8, "second" => 42, "std_offset" => 0, "time_zone" => "Etc/UTC", "utc_offset" => 0, "year" => 2019, "zone_abbr" => "UTC" } +# If you would like the date values to be preserved, you can set the following +# config value. This may be made the default in the future but is a breaking change. +# +# config :ex_machina, preserve_dates: true +# +# # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this # file won't be loaded nor affect the parent project. For this reason, diff --git a/config/test.exs b/config/test.exs index 007b6ed..37e3c47 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,5 +1,7 @@ use Mix.Config +config :ex_machina, preserve_dates: true + config :ex_machina, ExMachina.TestRepo, hostname: "localhost", database: "ex_machina_test", diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index bdb9593..ec27874 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -353,6 +353,14 @@ defmodule ExMachina.Ecto do Enum.map(values, &convert_atom_keys_to_strings/1) end + defp convert_atom_keys_to_strings(%NaiveDateTime{} = value) do + if Application.get_env(:ex_machina, :preserve_dates, false), do: value, else: Map.from_struct(value) |> convert_atom_keys_to_strings() + end + + defp convert_atom_keys_to_strings(%DateTime{} = value) do + if Application.get_env(:ex_machina, :preserve_dates, false), do: value, else: Map.from_struct(value) |> convert_atom_keys_to_strings() + end + defp convert_atom_keys_to_strings(%{__struct__: _} = record) when is_map(record) do Map.from_struct(record) |> convert_atom_keys_to_strings() end diff --git a/priv/test_repo/migrations/1_migrate_all.exs b/priv/test_repo/migrations/1_migrate_all.exs index 5373dd4..e0303da 100644 --- a/priv/test_repo/migrations/1_migrate_all.exs +++ b/priv/test_repo/migrations/1_migrate_all.exs @@ -40,6 +40,7 @@ defmodule ExMachina.TestRepo.Migrations.MigrateAll do add(:editor_id, :integer) add(:publisher_id, :integer) add(:visits, :decimal) + add(:published_at, :utc_datetime) end create table(:comments) do diff --git a/test/ex_machina/ecto_test.exs b/test/ex_machina/ecto_test.exs index b944e5f..ffe61be 100644 --- a/test/ex_machina/ecto_test.exs +++ b/test/ex_machina/ecto_test.exs @@ -261,6 +261,18 @@ defmodule ExMachina.EctoTest do %{"url" => "https://github.com", "rating" => 4} ] end + + test "string_params_for/2 converts map with datetime as expected" do + published_at = DateTime.utc_now(); + article_params = TestFactory.string_params_for(:article, published_at: published_at) + assert article_params["published_at"] == published_at + end + + test "string_params_for/2 converts map with naive datetime as expected" do + published_at = ~N[2000-01-01 23:00:07] + article_params = TestFactory.string_params_for(:article, published_at: published_at) + assert article_params["published_at"] == published_at + end end describe "params_with_assocs/2" do diff --git a/test/support/models/article.ex b/test/support/models/article.ex index b2cb3a6..941dd79 100644 --- a/test/support/models/article.ex +++ b/test/support/models/article.ex @@ -4,6 +4,7 @@ defmodule ExMachina.Article do schema "articles" do field(:title, :string) field(:visits, :decimal) + field(:published_at, :utc_datetime) belongs_to(:author, ExMachina.User) belongs_to(:editor, ExMachina.User) From fd6e85b17bbd466b0822e634f35a336579b09789 Mon Sep 17 00:00:00 2001 From: Jimmy Bosse Date: Wed, 17 Jan 2024 17:15:11 -0500 Subject: [PATCH 04/25] Update README.md (#435) I didn't understand why my file was not loaded when I moved some factories to a new location while following this README. This should help future users. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 9d9660a..31ff12d 100644 --- a/README.md +++ b/README.md @@ -382,6 +382,15 @@ defmodule MyApp.VideoFactory do end ``` +If you place your factories outside of `test/support` make sure they will compile by adding that directory to the compilation paths in your `mix.exs` file. For example for the `test/factories` files above you would modify your file like so: + +```elixir +# ./mix.exs +... + defp elixirc_paths(:test), do: ["lib", "test/factories", "test/support"] +... +``` + ## Ecto ### Ecto Associations From 2c2a309532f418083dac0df7bc74bf675056ad28 Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:25:16 -0500 Subject: [PATCH 05/25] chore: support common-config (#436) --- .github/CODEOWNERS | 5 +++ .github/workflows/common-config.yaml | 54 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/common-config.yaml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b06a787 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# Order alphabetically. +# Order is important. The last matching pattern takes the most precedence. + +# Default owners for everything in the repo. +* @beam-community/team diff --git a/.github/workflows/common-config.yaml b/.github/workflows/common-config.yaml new file mode 100644 index 0000000..36d4667 --- /dev/null +++ b/.github/workflows/common-config.yaml @@ -0,0 +1,54 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + +name: Common Config + +on: + push: + branches: + - main + paths: + - .github/workflows/common-config.yaml + repository_dispatch: + types: + - common-config + schedule: + - cron: "8 12 8 * *" + workflow_dispatch: {} + +concurrency: + group: Common Config + +jobs: + Sync: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + persist-credentials: true + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + elixir-version: "1.15" + otp-version: "26.0" + + - name: Sync + uses: stordco/actions-sync@v1 + with: + commit-message: "chore: sync files with beam-community/common-config" + pr-enabled: true + pr-labels: common-config + pr-title: "chore: sync files with beam-community/common-config" + pr-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + sync-auth: doomspork:${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + sync-branch: latest + sync-repository: github.com/beam-community/common-config.git From b06f4b6ebe323b8c0b4edcc961fbf4abb5a68bcd Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:27:17 -0500 Subject: [PATCH 06/25] chore: remove circleci, update tools-version (#438) --- .circleci/config.yml | 59 -------------------------------------------- .tool-versions | 4 +-- 2 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 118f3de..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,59 +0,0 @@ -version: 2 -jobs: - build: - parallelism: 1 - docker: - - image: circleci/elixir:1.7.4 - environment: - MIX_ENV: test - - image: circleci/postgres:13 - environment: - POSTGRES_USER: postgres - POSTGRES_DB: ex_machina_test - POSTGRES_PASSWORD: - - working_directory: ~/app - - steps: - - checkout - - - run: mix local.hex --force - - run: mix local.rebar --force - - - restore_cache: - keys: - - v2-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }} - - v2-mix-cache-{{ .Branch }} - - v2-mix-cache - - restore_cache: - keys: - - v2-build-cache-{{ .Branch }}-{{ checksum ".tool-versions" }} - - v2-build-cache-{{ .Branch }} - - v2-build-cache - - run: mix do deps.get, compile --warnings-as-errors - - save_cache: - key: v2-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }} - paths: "deps" - - save_cache: - key: v2-mix-cache-{{ .Branch }} - paths: "deps" - - save_cache: - key: v2-mix-cache - paths: "deps" - - save_cache: - key: v2-build-cache-{{ .Branch }}-{{ checksum ".tool-versions" }} - paths: "_build" - - save_cache: - key: v2-build-cache-{{ .Branch }} - paths: "_build" - - save_cache: - key: v2-build-cache - paths: "_build" - - - run: mix format --check-formatted - - - run: - name: Wait for DB - command: dockerize -wait tcp://localhost:5432 -timeout 1m - - - run: mix test diff --git a/.tool-versions b/.tool-versions index 8c647a8..f14e1e3 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -elixir 1.7.4-otp-21 -erlang 21.0 +elixir 1.15.4-otp-25 +erlang 25.3.2.5 From 8bb605725658a9dc36bd6e1f1579736f4b6514f4 Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:30:29 -0500 Subject: [PATCH 07/25] chore: Update and run formatter (#439) --- .formatter.exs | 5 ++++- lib/ex_machina/ecto.ex | 8 ++++++-- lib/ex_machina/ecto_strategy.ex | 4 +--- mix.lock | 26 +++++++++++++------------- test/ex_machina/ecto_test.exs | 2 +- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index d304ff3..eef1485 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,3 +1,6 @@ [ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] + import_deps: [:ecto, :ecto_sql], + inputs: ["*.{heex,ex,exs}", "{config,lib,priv,test}/**/*.{heex,ex,exs}"], + line_length: 120, + plugins: [] ] diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index ec27874..2bc0c57 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -354,11 +354,15 @@ defmodule ExMachina.Ecto do end defp convert_atom_keys_to_strings(%NaiveDateTime{} = value) do - if Application.get_env(:ex_machina, :preserve_dates, false), do: value, else: Map.from_struct(value) |> convert_atom_keys_to_strings() + if Application.get_env(:ex_machina, :preserve_dates, false), + do: value, + else: Map.from_struct(value) |> convert_atom_keys_to_strings() end defp convert_atom_keys_to_strings(%DateTime{} = value) do - if Application.get_env(:ex_machina, :preserve_dates, false), do: value, else: Map.from_struct(value) |> convert_atom_keys_to_strings() + if Application.get_env(:ex_machina, :preserve_dates, false), + do: value, + else: Map.from_struct(value) |> convert_atom_keys_to_strings() end defp convert_atom_keys_to_strings(%{__struct__: _} = record) when is_map(record) do diff --git a/lib/ex_machina/ecto_strategy.ex b/lib/ex_machina/ecto_strategy.ex index de4d502..2c8c66b 100644 --- a/lib/ex_machina/ecto_strategy.ex +++ b/lib/ex_machina/ecto_strategy.ex @@ -74,9 +74,7 @@ defmodule ExMachina.EctoStrategy do value _ -> - raise "Failed to cast `#{inspect(value)}` of type #{inspect(field_type)} in #{ - inspect(struct) - }." + raise "Failed to cast `#{inspect(value)}` of type #{inspect(field_type)} in #{inspect(struct)}." end end diff --git a/mix.lock b/mix.lock index 80a34b7..144f721 100644 --- a/mix.lock +++ b/mix.lock @@ -1,21 +1,21 @@ %{ - "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []}, - "db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, - "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, - "ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, + "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, + "db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "ced0780bed50430f770b74fcde870c4a50c815124ecf9fee20d67a465966eb4f"}, + "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm", "771ea78576e5fa505ad58a834f57915c7f5f9df11c87a598a01fdf6065ccfb5d"}, + "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"}, + "ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "8acd54c5c92c7dbe5a9e76adc22ffb4e2e76e5298989eed2068a4f04bc8e6fef"}, + "ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e5bd47a499d27084afaa3c2154cfedb478ea2fcc926ef59fa515ee089701e390"}, "esqlite": {:hex, :esqlite, "0.2.1"}, - "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, - "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, + "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, "pipe": {:hex, :pipe, "0.0.2"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, - "postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"}, + "postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "a20f189bdd5a219c484818fde18e09ace20cd15fe630a828fde70bd6efdeb23b"}, "sqlite_ecto": {:hex, :sqlite_ecto, "1.0.2"}, "sqlitex": {:hex, :sqlitex, "0.8.2"}, - "telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm"}, + "telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm", "63d9f37d319ff331a51f6221310deb5aac8ea3dcf5e0369d689121b5e52f72d4"}, } diff --git a/test/ex_machina/ecto_test.exs b/test/ex_machina/ecto_test.exs index ffe61be..b58e126 100644 --- a/test/ex_machina/ecto_test.exs +++ b/test/ex_machina/ecto_test.exs @@ -263,7 +263,7 @@ defmodule ExMachina.EctoTest do end test "string_params_for/2 converts map with datetime as expected" do - published_at = DateTime.utc_now(); + published_at = DateTime.utc_now() article_params = TestFactory.string_params_for(:article, published_at: published_at) assert article_params["published_at"] == published_at end From a32783031b21cd91bced561d4a30e9031f8a77e9 Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:40:33 -0500 Subject: [PATCH 08/25] chore: Resolve config warning (#440) --- config/config.exs | 2 +- config/test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index 991d82a..2288e2d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config # By default, ExMachina will convert datetime values to a map with string # keys such as diff --git a/config/test.exs b/config/test.exs index 37e3c47..5cfda9d 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :ex_machina, preserve_dates: true From c6c76f044d4fe8f57d82daed50800f8d43bd15b2 Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:42:45 -0500 Subject: [PATCH 09/25] chore: update mix.exs and deps --- mix.exs | 60 ++++++++++++++++++++++++++++++++++---------------------- mix.lock | 39 ++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/mix.exs b/mix.exs index aa6c07f..d7cad75 100644 --- a/mix.exs +++ b/mix.exs @@ -1,56 +1,70 @@ defmodule ExMachina.Mixfile do use Mix.Project - @project_url "https://github.com/thoughtbot/ex_machina" - @version "2.7.0" - - def project() do + def project do [ app: :ex_machina, - version: @version, - elixir: ">= 1.4.0", description: "A factory library by the creators of FactoryBot (née FactoryGirl)", - source_url: @project_url, - homepage_url: @project_url, + version: "2.7.0", + elixir: "~> 1.11", elixirc_paths: elixirc_paths(Mix.env()), - build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, + deps: deps(), + docs: docs(), package: package(), - docs: [main: "readme", extras: ["README.md"]], - deps: deps() + source_url: "https://github.com/beam-community/ex_machina", + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + coveralls: :test, + "coveralls.detail": :test, + "coveralls.html": :test, + "coveralls.circle": :test + ] ] end - def application() do + def application do [ extra_applications: [:logger], mod: {ExMachina, []} ] end - defp deps() do + defp deps do [ - {:ex_doc, "~> 0.14", only: :dev}, - {:earmark, ">= 0.0.0", only: :dev}, {:ecto, "~> 2.2 or ~> 3.0", optional: true}, {:ecto_sql, "~> 3.0", optional: true}, + + # Dev and Test dependencies + {:credo, "~> 1.6", only: :test, runtime: false}, + {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, + {:doctor, "~> 0.21.0", only: [:dev, :test], runtime: false}, + {:excoveralls, "~> 0.17.1", only: :test}, + {:ex_doc, "~> 0.28", only: [:dev, :test], runtime: false}, {:jason, "~> 1.0", only: :test}, - {:postgrex, "~> 0.14.0", only: :test} + {:postgrex, "~> 0.17", only: :test} + ] + end + + defp docs do + [ + extras: ["README.md", "CHANGELOG.md", "LICENSE.md"], + main: "readme" ] end - defp package() do + defp package do [ - maintainers: ["German Velasco"], + maintainers: ["BEAM Community"], + files: ~w(lib mix.exs .formatter.exs README.md CHANGELOG.md LICENSE.md), licenses: ["MIT"], links: %{ - "GitHub" => @project_url, - "Made by thoughtbot" => "https://thoughtbot.com/services/elixir-phoenix" + Changelog: "https://github.com/beam-community/ex_machina/releases", + GitHub: "https://github.com/beam-community/ex_machina" } ] end - defp elixirc_paths(:test), do: elixirc_paths() ++ ["test/support"] - defp elixirc_paths(_), do: elixirc_paths() - defp elixirc_paths(), do: ["lib"] + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] end diff --git a/mix.lock b/mix.lock index 144f721..0e1f4c6 100644 --- a/mix.lock +++ b/mix.lock @@ -1,21 +1,22 @@ %{ - "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, - "db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "ced0780bed50430f770b74fcde870c4a50c815124ecf9fee20d67a465966eb4f"}, - "decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm", "771ea78576e5fa505ad58a834f57915c7f5f9df11c87a598a01fdf6065ccfb5d"}, - "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"}, - "ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "8acd54c5c92c7dbe5a9e76adc22ffb4e2e76e5298989eed2068a4f04bc8e6fef"}, - "ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e5bd47a499d27084afaa3c2154cfedb478ea2fcc926ef59fa515ee089701e390"}, - "esqlite": {:hex, :esqlite, "0.2.1"}, - "ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, - "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"}, - "pipe": {:hex, :pipe, "0.0.2"}, - "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, - "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, - "postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "a20f189bdd5a219c484818fde18e09ace20cd15fe630a828fde70bd6efdeb23b"}, - "sqlite_ecto": {:hex, :sqlite_ecto, "1.0.2"}, - "sqlitex": {:hex, :sqlitex, "0.8.2"}, - "telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm", "63d9f37d319ff331a51f6221310deb5aac8ea3dcf5e0369d689121b5e52f72d4"}, + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, + "credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"}, + "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, + "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, + "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, + "doctor": {:hex, :doctor, "0.21.0", "20ef89355c67778e206225fe74913e96141c4d001cb04efdeba1a2a9704f1ab5", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a227831daa79784eb24cdeedfa403c46a4cb7d0eab0e31232ec654314447e4e0"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, + "ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"}, + "ecto_sql": {:hex, :ecto_sql, "3.11.1", "e9abf28ae27ef3916b43545f9578b4750956ccea444853606472089e7d169470", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ce14063ab3514424276e7e360108ad6c2308f6d88164a076aac8a387e1fea634"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"}, + "excoveralls": {:hex, :excoveralls, "0.17.1", "83fa7906ef23aa7fc8ad7ee469c357a63b1b3d55dd701ff5b9ce1f72442b2874", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "95bc6fda953e84c60f14da4a198880336205464e75383ec0f570180567985ae0"}, + "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, + "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, + "postgrex": {:hex, :postgrex, "0.17.4", "5777781f80f53b7c431a001c8dad83ee167bcebcf3a793e3906efff680ab62b3", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "6458f7d5b70652bc81c3ea759f91736c16a31be000f306d3c64bcdfe9a18b3cc"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, } From 5aa4f01c8234a76cb3a41fa43e6da7cbd668ba03 Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:50:28 -0500 Subject: [PATCH 10/25] chore: Satisfy Credo consistency check --- lib/ex_machina/ecto.ex | 12 ++++++------ mix.exs | 3 +-- mix.lock | 3 +++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index 2bc0c57..de6f143 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -211,7 +211,7 @@ defmodule ExMachina.Ecto do |> convert_atom_keys_to_strings end - defp recursively_strip(record = %{__struct__: _}) do + defp recursively_strip(%{__struct__: _} = record) do record |> set_persisted_belongs_to_ids |> handle_assocs @@ -222,7 +222,7 @@ defmodule ExMachina.Ecto do defp recursively_strip(record), do: record - defp handle_assocs(record = %{__struct__: struct}) do + defp handle_assocs(%{__struct__: struct} = record) do Enum.reduce(struct.__schema__(:associations), record, fn association_name, record -> case struct.__schema__(:association, association_name) do %{__struct__: Ecto.Association.BelongsTo} -> @@ -254,7 +254,7 @@ defmodule ExMachina.Ecto do end end - defp handle_embeds(record = %{__struct__: struct}) do + defp handle_embeds(%{__struct__: struct} = record) do Enum.reduce(struct.__schema__(:embeds), record, fn embed_name, record -> record |> Map.get(embed_name) @@ -277,7 +277,7 @@ defmodule ExMachina.Ecto do end end - defp set_persisted_belongs_to_ids(record = %{__struct__: struct}) do + defp set_persisted_belongs_to_ids(%{__struct__: struct} = record) do Enum.reduce(struct.__schema__(:associations), record, fn association_name, record -> association = struct.__schema__(:association, association_name) @@ -302,7 +302,7 @@ defmodule ExMachina.Ecto do Map.put(record, association.owner_key, primary_key) end - defp insert_belongs_to_assocs(record = %{__struct__: struct}, module) do + defp insert_belongs_to_assocs(%{__struct__: struct} = record, module) do Enum.reduce(struct.__schema__(:associations), record, fn association_name, record -> case struct.__schema__(:association, association_name) do association = %{__struct__: Ecto.Association.BelongsTo} -> @@ -326,7 +326,7 @@ defmodule ExMachina.Ecto do end @doc false - def drop_ecto_fields(record = %{__struct__: struct}) do + def drop_ecto_fields(%{__struct__: struct} = record) do record |> Map.from_struct() |> Map.delete(:__meta__) diff --git a/mix.exs b/mix.exs index d7cad75..6a1298d 100644 --- a/mix.exs +++ b/mix.exs @@ -36,12 +36,11 @@ defmodule ExMachina.Mixfile do {:ecto_sql, "~> 3.0", optional: true}, # Dev and Test dependencies - {:credo, "~> 1.6", only: :test, runtime: false}, + {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, {:doctor, "~> 0.21.0", only: [:dev, :test], runtime: false}, {:excoveralls, "~> 0.17.1", only: :test}, {:ex_doc, "~> 0.28", only: [:dev, :test], runtime: false}, - {:jason, "~> 1.0", only: :test}, {:postgrex, "~> 0.17", only: :test} ] end diff --git a/mix.lock b/mix.lock index 0e1f4c6..287f99c 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,10 @@ %{ + "benchee": {:hex, :benchee, "1.3.0", "f64e3b64ad3563fa9838146ddefb2d2f94cf5b473bdfd63f5ca4d0657bf96694", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "34f4294068c11b2bd2ebf2c59aac9c7da26ffa0068afdf3419f1b176e16c5f81"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"}, "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, + "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, "doctor": {:hex, :doctor, "0.21.0", "20ef89355c67778e206225fe74913e96141c4d001cb04efdeba1a2a9704f1ab5", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a227831daa79784eb24cdeedfa403c46a4cb7d0eab0e31232ec654314447e4e0"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, @@ -18,5 +20,6 @@ "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "postgrex": {:hex, :postgrex, "0.17.4", "5777781f80f53b7c431a001c8dad83ee167bcebcf3a793e3906efff680ab62b3", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "6458f7d5b70652bc81c3ea759f91736c16a31be000f306d3c64bcdfe9a18b3cc"}, + "statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, } From 821a61a351676c2fee717451d8881059dc04730d Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Wed, 17 Jan 2024 17:51:12 -0500 Subject: [PATCH 11/25] chore: Clear up log level warning --- config/test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/test.exs b/config/test.exs index 5cfda9d..02efe67 100644 --- a/config/test.exs +++ b/config/test.exs @@ -8,4 +8,4 @@ config :ex_machina, ExMachina.TestRepo, pool: Ecto.Adapters.SQL.Sandbox, username: "postgres" -config :logger, level: :warn +config :logger, level: :warning From 72e40389a273a38be5f8dd96aef02976258212aa Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Thu, 18 Jan 2024 15:44:10 -0500 Subject: [PATCH 12/25] chore: sync files with beam-community/common-config (#437) * chore: sync files with beam-community/common-config * chore: Format Credo config * chore: Satisfy Credo refactoring checks * chore: Credo code readability changes * chore: Credo refactoring opportunity * chore: Update deps * add postgres service for test --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Blake Kostner --- .credo.exs | 179 ++++++++++++++++++++++ .formatter.exs | 2 + .github/release-please-config.json | 39 +++++ .github/workflows/ci.yaml | 116 ++++++++++++++ .github/workflows/pr.yaml | 35 +++++ .github/workflows/production.yaml | 15 ++ .github/workflows/release.yaml | 23 +++ lib/ex_machina.ex | 59 +++---- lib/ex_machina/ecto.ex | 163 ++++++++++---------- lib/ex_machina/strategy.ex | 26 ++-- lib/ex_machina/undefined_factory_error.ex | 21 +++ mix.lock | 3 - test/ex_machina/ecto_strategy_test.exs | 8 +- test/ex_machina/ecto_test.exs | 4 +- test/ex_machina/strategy_test.exs | 2 +- test/support/models/invalid_type.ex | 2 + 16 files changed, 555 insertions(+), 142 deletions(-) create mode 100644 .credo.exs create mode 100644 .github/release-please-config.json create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/production.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 lib/ex_machina/undefined_factory_error.ex diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..f078317 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,179 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + +# This file contains the configuration for Credo and you are probably reading +# this after creating it with `mix credo.gen.config`. +# +# If you find anything wrong or unclear in this file, please report an +# issue on GitHub: https://github.com/rrrene/credo/issues +# +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any config using `mix credo -C `. If no config name is given + # "default" is used. + # + name: "default", + # + # These are the files included in the analysis: + files: %{ + # + # You can give explicit globs or simply directories. + # In the latter case `**/*.{ex,exs}` will be used. + # + included: ["config/", "lib/", "priv/", "test/"], + excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] + }, + # + # Load and configure plugins here: + # + plugins: [], + # + # If you create your own checks, you must specify the source files for + # them here, so they can be loaded by Credo before running the analysis. + # + requires: [], + # + # If you want to enforce a style guide and need a more traditional linting + # experience, you can change `strict` to `true` below: + # + strict: true, + # + # To modify the timeout for parsing files, change this value: + # + parse_timeout: 5000, + # + # If you want to use uncolored output by default, you can change `color` + # to `false` below: + # + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: [ + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames, []}, + {Credo.Check.Consistency.LineEndings, []}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, []}, + {Credo.Check.Consistency.ParameterPatternMatching, []}, + {Credo.Check.Consistency.SpaceAroundOperators, []}, + {Credo.Check.Consistency.SpaceInParentheses, []}, + {Credo.Check.Consistency.TabsOrSpaces, []}, + {Credo.Check.Consistency.UnusedVariableNames, false}, + + # + ## Design Checks + # + # You can customize the priority of any check + # Priority values are: `low, normal, high, higher` + # + {Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 2]}, + {Credo.Check.Design.DuplicatedCode, false}, + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + # + {Credo.Check.Design.TagTODO, [exit_status: 2]}, + {Credo.Check.Design.TagFIXME, []}, + + # + ## Readability Checks + # + {Credo.Check.Readability.AliasAs, false}, + {Credo.Check.Readability.AliasOrder, []}, + {Credo.Check.Readability.BlockPipe, []}, + {Credo.Check.Readability.FunctionNames, []}, + {Credo.Check.Readability.ImplTrue, []}, + {Credo.Check.Readability.LargeNumbers, [trailing_digits: 2]}, + {Credo.Check.Readability.MaxLineLength, false}, + {Credo.Check.Readability.ModuleAttributeNames, []}, + {Credo.Check.Readability.ModuleDoc, false}, + {Credo.Check.Readability.ModuleNames, []}, + {Credo.Check.Readability.MultiAlias, false}, + {Credo.Check.Readability.NestedFunctionCalls, []}, + {Credo.Check.Readability.ParenthesesInCondition, []}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []}, + {Credo.Check.Readability.PredicateFunctionNames, []}, + {Credo.Check.Readability.PreferImplicitTry, []}, + {Credo.Check.Readability.RedundantBlankLines, []}, + {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SeparateAliasRequire, []}, + {Credo.Check.Readability.SinglePipe, []}, + {Credo.Check.Readability.SpaceAfterCommas, []}, + {Credo.Check.Readability.Specs, false}, + {Credo.Check.Readability.StrictModuleLayout, + [ + order: + ~w(moduledoc behaviour use import require alias module_attribute defstruct callback macrocallback optional_callback)a, + ignore: [:type] + ]}, + {Credo.Check.Readability.StringSigils, []}, + {Credo.Check.Readability.TrailingBlankLine, []}, + {Credo.Check.Readability.TrailingWhiteSpace, []}, + {Credo.Check.Readability.UnnecessaryAliasExpansion, []}, + {Credo.Check.Readability.VariableNames, []}, + {Credo.Check.Readability.WithCustomTaggedTuple, []}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.ABCSize, false}, + {Credo.Check.Refactor.AppendSingleItem, []}, + {Credo.Check.Refactor.CondStatements, []}, + {Credo.Check.Refactor.CyclomaticComplexity, []}, + {Credo.Check.Refactor.DoubleBooleanNegation, []}, + {Credo.Check.Refactor.FunctionArity, []}, + {Credo.Check.Refactor.LongQuoteBlocks, []}, + # {Credo.Check.Refactor.MapInto, []}, + {Credo.Check.Refactor.MatchInCondition, []}, + {Credo.Check.Refactor.ModuleDependencies, false}, + {Credo.Check.Refactor.NegatedConditionsInUnless, []}, + {Credo.Check.Refactor.NegatedConditionsWithElse, []}, + {Credo.Check.Refactor.NegatedIsNil, []}, + {Credo.Check.Refactor.Nesting, []}, + {Credo.Check.Refactor.PipeChainStart, []}, + {Credo.Check.Refactor.UnlessWithElse, []}, + {Credo.Check.Refactor.VariableRebinding, false}, + {Credo.Check.Refactor.WithClauses, []}, + + # + ## Warnings + # + {Credo.Check.Warning.ApplicationConfigInModuleAttribute, []}, + {Credo.Check.Warning.BoolOperationOnSameValues, []}, + {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, + {Credo.Check.Warning.IExPry, []}, + {Credo.Check.Warning.IoInspect, []}, + {Credo.Check.Warning.LeakyEnvironment, []}, + # {Credo.Check.Warning.LazyLogging, []}, + {Credo.Check.Warning.MapGetUnsafePass, []}, + # disabling this check by default, as if not included, it will be + # run on version 1.7.0 and above + {Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, false}, + {Credo.Check.Warning.MixEnv, []}, + {Credo.Check.Warning.OperationOnSameValues, []}, + {Credo.Check.Warning.OperationWithConstantResult, []}, + {Credo.Check.Warning.RaiseInsideRescue, []}, + {Credo.Check.Warning.UnsafeExec, []}, + {Credo.Check.Warning.UnsafeToAtom, []}, + {Credo.Check.Warning.UnusedEnumOperation, []}, + {Credo.Check.Warning.UnusedFileOperation, []}, + {Credo.Check.Warning.UnusedKeywordOperation, []}, + {Credo.Check.Warning.UnusedListOperation, []}, + {Credo.Check.Warning.UnusedPathOperation, []}, + {Credo.Check.Warning.UnusedRegexOperation, []}, + {Credo.Check.Warning.UnusedStringOperation, []}, + {Credo.Check.Warning.UnusedTupleOperation, []} + ] + } + ] +} diff --git a/.formatter.exs b/.formatter.exs index eef1485..e5aed66 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,3 +1,5 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + [ import_deps: [:ecto, :ecto_sql], inputs: ["*.{heex,ex,exs}", "{config,lib,priv,test}/**/*.{heex,ex,exs}"], diff --git a/.github/release-please-config.json b/.github/release-please-config.json new file mode 100644 index 0000000..cd8b23a --- /dev/null +++ b/.github/release-please-config.json @@ -0,0 +1,39 @@ +{ + "$comment": "This file is synced with beam-community/common-config. Any changes will be overwritten.", + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "changelog-sections": [ + { + "type": "feat", + "section": "Features", + "hidden": false + }, + { + "type": "fix", + "section": "Bug Fixes", + "hidden": false + }, + { + "type": "chore", + "section": "Miscellaneous", + "hidden": false + } + ], + "draft": false, + "draft-pull-request": false, + "packages": { + ".": { + "extra-files": [ + "README.md" + ], + "release-type": "elixir" + } + }, + "plugins": [ + { + "type": "sentence-case" + } + ], + "prerelease": false, + "pull-request-header": "An automated release has been created for you.", + "separate-pull-requests": true +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..bebad11 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,116 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + +name: CI + +on: + merge_group: + pull_request: + types: + - opened + - reopened + - synchronize + push: + branches: + - main + workflow_call: + secrets: + GH_PERSONAL_ACCESS_TOKEN: + required: true + workflow_dispatch: + +concurrency: + group: CI ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + Credo: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + + - name: Credo + run: mix credo --strict + + Dependencies: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + + - name: Unused + run: mix deps.unlock --check-unused + + Dialyzer: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + + - name: Dialyzer + run: mix dialyzer --format github + + Format: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + + - name: Format + run: mix format --check-formatted + + Test: + runs-on: ubuntu-latest + + env: + MIX_ENV: test + + services: + postgres: + image: postgres:16-alpine + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_INITDB_ARGS: "--nosync" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + + - name: Compile + run: mix compile --warnings-as-errors + + - name: Test + run: mix test + diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..5e2628a --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,35 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + +name: PR + +on: + merge_group: + pull_request: + types: + - edited + - opened + - reopened + - synchronize + +jobs: + Title: + if: ${{ github.event_name == 'pull_request' }} + name: Check Title + runs-on: ubuntu-latest + + steps: + - name: Check + uses: stordco/actions-pr-title@v1.0.0 + with: + regex: '^(feat!|fix!|fix|feat|chore)(\(\w+\))?:\s(\[#\d{1,5}\])?.*$' + hint: | + Your PR title does not match the Conventional Commits convention. Please rename your PR to match one of the following formats: + + fix: [#123] some title of the PR + fix(scope): [#123] some title of the PR + feat: [#1234] some title of the PR + chore: update some action + + Note: Adding ! (i.e. `feat!:`) represents a breaking change and will result in a SemVer major release. + + See https://www.conventionalcommits.org/en/v1.0.0/ for more information. diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml new file mode 100644 index 0000000..2a6b98f --- /dev/null +++ b/.github/workflows/production.yaml @@ -0,0 +1,15 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + +name: Production + +on: + release: + types: + - released + - prereleased + workflow_dispatch: + +concurrency: + group: Production + +jobs: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..40ef723 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,23 @@ +# This file is synced with beam-community/common-config. Any changes will be overwritten. + +name: Release + +on: + push: + branches: + - main + +jobs: + Please: + runs-on: ubuntu-latest + + steps: + - id: release + name: Release + uses: google-github-actions/release-please-action@v3 + with: + command: manifest + config-file: .github/release-please-config.json + manifest-file: .github/release-please-manifest.json + release-type: elixir + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} diff --git a/lib/ex_machina.ex b/lib/ex_machina.ex index 3a8f7ff..04be659 100644 --- a/lib/ex_machina.ex +++ b/lib/ex_machina.ex @@ -4,30 +4,16 @@ defmodule ExMachina do In depth examples are in the [README](readme.html) """ + use Application - defmodule UndefinedFactoryError do - @moduledoc """ - Error raised when trying to build or create a factory that is undefined. - """ - - defexception [:message] - - def exception(factory_name) do - message = """ - No factory defined for #{inspect(factory_name)}. - - Please check for typos or define your factory: - - def #{factory_name}_factory do - ... - end - """ - - %UndefinedFactoryError{message: message} - end - end + alias ExMachina.UndefinedFactoryError - use Application + @callback build(factory_name :: atom) :: any + @callback build(factory_name :: atom, attrs :: keyword | map) :: any + @callback build_list(number_of_records :: integer, factory_name :: atom) :: list + @callback build_list(number_of_records :: integer, factory_name :: atom, attrs :: keyword | map) :: list + @callback build_pair(factory_name :: atom) :: list + @callback build_pair(factory_name :: atom, attrs :: keyword | map) :: list @doc false def start(_type, _args), do: ExMachina.Sequence.start_link() @@ -45,6 +31,8 @@ defmodule ExMachina do evaluate_lazy_attributes: 1 ] + alias ExMachina.UndefinedFactoryError + def build(factory_name, attrs \\ %{}) do ExMachina.build(__MODULE__, factory_name, attrs) end @@ -221,10 +209,6 @@ defmodule ExMachina do # Returns %Article{title: "hello world", slug: "hello-world"} build(:article, title: "hello world") """ - @callback build(factory_name :: atom) :: any - @callback build(factory_name :: atom, attrs :: keyword | map) :: any - - @doc false def build(module, factory_name, attrs \\ %{}) do attrs = Enum.into(attrs, %{}) @@ -235,7 +219,8 @@ defmodule ExMachina do apply(module, function_name, [attrs]) factory_without_attributes_defined?(module, function_name) -> - apply(module, function_name, []) + module + |> apply(function_name, []) |> merge_attributes(attrs) |> evaluate_lazy_attributes() @@ -248,6 +233,7 @@ defmodule ExMachina do factory_name |> Atom.to_string() |> Kernel.<>("_factory") + # credo:disable-for-next-line Credo.Check.Warning.UnsafeToAtom |> String.to_atom() end @@ -343,10 +329,6 @@ defmodule ExMachina do # Returns a list of 2 users build_pair(:user) """ - @callback build_pair(factory_name :: atom) :: list - @callback build_pair(factory_name :: atom, attrs :: keyword | map) :: list - - @doc false def build_pair(module, factory_name, attrs \\ %{}) do ExMachina.build_list(module, 2, factory_name, attrs) end @@ -359,16 +341,13 @@ defmodule ExMachina do # Returns a list of 3 users build_list(3, :user) """ - @callback build_list(number_of_records :: integer, factory_name :: atom) :: list - @callback build_list(number_of_records :: integer, factory_name :: atom, attrs :: keyword | map) :: - list - - @doc false def build_list(module, number_of_records, factory_name, attrs \\ %{}) do - Stream.repeatedly(fn -> - ExMachina.build(module, factory_name, attrs) - end) - |> Enum.take(number_of_records) + stream = + Stream.repeatedly(fn -> + ExMachina.build(module, factory_name, attrs) + end) + + Enum.take(stream, number_of_records) end defmacro __before_compile__(_env) do diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index de6f143..7a1bded 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -12,43 +12,7 @@ defmodule ExMachina.Ecto do More in-depth examples are in the [README](readme.html). """ - defmacro __using__(opts) do - verify_ecto_dep() - - quote do - use ExMachina - use ExMachina.EctoStrategy, repo: unquote(Keyword.get(opts, :repo)) - - def params_for(factory_name, attrs \\ %{}) do - ExMachina.Ecto.params_for(__MODULE__, factory_name, attrs) - end - - def string_params_for(factory_name, attrs \\ %{}) do - ExMachina.Ecto.string_params_for(__MODULE__, factory_name, attrs) - end - - def params_with_assocs(factory_name, attrs \\ %{}) do - ExMachina.Ecto.params_with_assocs(__MODULE__, factory_name, attrs) - end - - def string_params_with_assocs(factory_name, attrs \\ %{}) do - ExMachina.Ecto.string_params_with_assocs(__MODULE__, factory_name, attrs) - end - end - end - - defp verify_ecto_dep do - unless Code.ensure_loaded?(Ecto) do - raise "You tried to use ExMachina.Ecto, but the Ecto module is not loaded. " <> - "Please add ecto to your dependencies." - end - end - @doc """ - Builds a factory and inserts it into the database. - - The arguments are the same as `c:ExMachina.build/2`. - """ @callback insert(factory_name :: atom) :: any @callback insert(factory_name :: atom, attrs :: keyword | map) :: any @@ -121,13 +85,6 @@ defmodule ExMachina.Ecto do @callback params_for(factory_name :: atom) :: %{optional(atom) => any} @callback params_for(factory_name :: atom, attrs :: keyword | map) :: %{optional(atom) => any} - @doc false - def params_for(module, factory_name, attrs \\ %{}) do - factory_name - |> module.build(attrs) - |> recursively_strip - end - @doc """ Similar to `c:params_for/2` but converts atom keys to strings in returned map. @@ -148,13 +105,6 @@ defmodule ExMachina.Ecto do optional(String.t()) => any } - @doc false - def string_params_for(module, factory_name, attrs \\ %{}) do - module - |> params_for(factory_name, attrs) - |> convert_atom_keys_to_strings - end - @doc """ Similar to `c:params_for/2` but inserts all `belongs_to` associations and sets the foreign keys. @@ -174,15 +124,6 @@ defmodule ExMachina.Ecto do @callback params_with_assocs(factory_name :: atom, attrs :: keyword | map) :: %{ optional(atom) => any } - - @doc false - def params_with_assocs(module, factory_name, attrs \\ %{}) do - factory_name - |> module.build(attrs) - |> insert_belongs_to_assocs(module) - |> recursively_strip - end - @doc """ Similar to `c:params_with_assocs/2` but converts atom keys to strings in returned map. @@ -204,6 +145,53 @@ defmodule ExMachina.Ecto do optional(String.t()) => any } + defmacro __using__(opts) do + verify_ecto_dep() + + quote do + use ExMachina + use ExMachina.EctoStrategy, repo: unquote(Keyword.get(opts, :repo)) + + def params_for(factory_name, attrs \\ %{}) do + ExMachina.Ecto.params_for(__MODULE__, factory_name, attrs) + end + + def string_params_for(factory_name, attrs \\ %{}) do + ExMachina.Ecto.string_params_for(__MODULE__, factory_name, attrs) + end + + def params_with_assocs(factory_name, attrs \\ %{}) do + ExMachina.Ecto.params_with_assocs(__MODULE__, factory_name, attrs) + end + + def string_params_with_assocs(factory_name, attrs \\ %{}) do + ExMachina.Ecto.string_params_with_assocs(__MODULE__, factory_name, attrs) + end + end + end + + @doc false + def params_for(module, factory_name, attrs \\ %{}) do + factory_name + |> module.build(attrs) + |> recursively_strip + end + + @doc false + def string_params_for(module, factory_name, attrs \\ %{}) do + module + |> params_for(factory_name, attrs) + |> convert_atom_keys_to_strings + end + + @doc false + def params_with_assocs(module, factory_name, attrs \\ %{}) do + factory_name + |> module.build(attrs) + |> insert_belongs_to_assocs(module) + |> recursively_strip + end + @doc false def string_params_with_assocs(module, factory_name, attrs \\ %{}) do module @@ -223,7 +211,9 @@ defmodule ExMachina.Ecto do defp recursively_strip(record), do: record defp handle_assocs(%{__struct__: struct} = record) do - Enum.reduce(struct.__schema__(:associations), record, fn association_name, record -> + associations = struct.__schema__(:associations) + + Enum.reduce(associations, record, fn association_name, record -> case struct.__schema__(:association, association_name) do %{__struct__: Ecto.Association.BelongsTo} -> Map.delete(record, association_name) @@ -255,7 +245,9 @@ defmodule ExMachina.Ecto do end defp handle_embeds(%{__struct__: struct} = record) do - Enum.reduce(struct.__schema__(:embeds), record, fn embed_name, record -> + embeds = struct.__schema__(:embeds) + + Enum.reduce(embeds, record, fn embed_name, record -> record |> Map.get(embed_name) |> handle_embed(record, embed_name) @@ -278,21 +270,15 @@ defmodule ExMachina.Ecto do end defp set_persisted_belongs_to_ids(%{__struct__: struct} = record) do - Enum.reduce(struct.__schema__(:associations), record, fn association_name, record -> - association = struct.__schema__(:association, association_name) + associations = struct.__schema__(:associations) - case association do - %{__struct__: Ecto.Association.BelongsTo} -> - case Map.get(record, association_name) do - belongs_to = %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} -> - set_belongs_to_primary_key(record, belongs_to, association) - - _ -> - record - end + Enum.reduce(associations, record, fn association_name, record -> + association = struct.__schema__(:association, association_name) - _ -> - record + with %{__struct__: Ecto.Association.BelongsTo} <- association, + %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} = belongs_to <- + Map.get(record, association_name) do + set_belongs_to_primary_key(record, belongs_to, association) end end) end @@ -303,7 +289,9 @@ defmodule ExMachina.Ecto do end defp insert_belongs_to_assocs(%{__struct__: struct} = record, module) do - Enum.reduce(struct.__schema__(:associations), record, fn association_name, record -> + assocations = struct.__schema__(:associations) + + Enum.reduce(assocations, record, fn association_name, record -> case struct.__schema__(:association, association_name) do association = %{__struct__: Ecto.Association.BelongsTo} -> insert_built_belongs_to_assoc(module, association, record) @@ -354,19 +342,23 @@ defmodule ExMachina.Ecto do end defp convert_atom_keys_to_strings(%NaiveDateTime{} = value) do - if Application.get_env(:ex_machina, :preserve_dates, false), - do: value, - else: Map.from_struct(value) |> convert_atom_keys_to_strings() + if Application.get_env(:ex_machina, :preserve_dates, false) do + value + else + value |> Map.from_struct() |> convert_atom_keys_to_strings() + end end defp convert_atom_keys_to_strings(%DateTime{} = value) do - if Application.get_env(:ex_machina, :preserve_dates, false), - do: value, - else: Map.from_struct(value) |> convert_atom_keys_to_strings() + if Application.get_env(:ex_machina, :preserve_dates, false) do + value + else + value |> Map.from_struct() |> convert_atom_keys_to_strings() + end end defp convert_atom_keys_to_strings(%{__struct__: _} = record) when is_map(record) do - Map.from_struct(record) |> convert_atom_keys_to_strings() + record |> Map.from_struct() |> convert_atom_keys_to_strings() end defp convert_atom_keys_to_strings(record) when is_map(record) do @@ -376,4 +368,11 @@ defmodule ExMachina.Ecto do end defp convert_atom_keys_to_strings(value), do: value + + defp verify_ecto_dep do + unless Code.ensure_loaded?(Ecto) do + raise "You tried to use ExMachina.Ecto, but the Ecto module is not loaded. " <> + "Please add ecto to your dependencies." + end + end end diff --git a/lib/ex_machina/strategy.ex b/lib/ex_machina/strategy.ex index 3ca22df..2fb4fa7 100644 --- a/lib/ex_machina/strategy.ex +++ b/lib/ex_machina/strategy.ex @@ -1,3 +1,4 @@ +# credo:disable-for-this-file Credo.Check.Warning.UnsafeToAtom defmodule ExMachina.Strategy do @moduledoc ~S""" Module for making new strategies for working with factories @@ -74,7 +75,8 @@ defmodule ExMachina.Strategy do def unquote(function_name)(already_built_record, function_opts) when is_map(already_built_record) do opts = - Map.new(unquote(opts)) + unquote(opts) + |> Map.new() |> Map.merge(%{factory_module: __MODULE__}) apply( @@ -85,7 +87,7 @@ defmodule ExMachina.Strategy do end def unquote(function_name)(already_built_record) when is_map(already_built_record) do - opts = Map.new(unquote(opts)) |> Map.merge(%{factory_module: __MODULE__}) + opts = unquote(opts) |> Map.new() |> Map.merge(%{factory_module: __MODULE__}) apply( unquote(custom_strategy_module), @@ -121,17 +123,21 @@ defmodule ExMachina.Strategy do end def unquote(:"#{function_name}_list")(number_of_records, factory_name, attrs, opts) do - Stream.repeatedly(fn -> - unquote(function_name)(factory_name, attrs, opts) - end) - |> Enum.take(number_of_records) + stream = + Stream.repeatedly(fn -> + unquote(function_name)(factory_name, attrs, opts) + end) + + Enum.take(stream, number_of_records) end def unquote(:"#{function_name}_list")(number_of_records, factory_name, attrs \\ %{}) do - Stream.repeatedly(fn -> - unquote(function_name)(factory_name, attrs) - end) - |> Enum.take(number_of_records) + stream = + Stream.repeatedly(fn -> + unquote(function_name)(factory_name, attrs) + end) + + Enum.take(stream, number_of_records) end end end diff --git a/lib/ex_machina/undefined_factory_error.ex b/lib/ex_machina/undefined_factory_error.ex new file mode 100644 index 0000000..5cb2ea0 --- /dev/null +++ b/lib/ex_machina/undefined_factory_error.ex @@ -0,0 +1,21 @@ +defmodule ExMachina.UndefinedFactoryError do + @moduledoc """ + Error raised when trying to build or create a factory that is undefined. + """ + + defexception [:message] + + def exception(factory_name) do + message = """ + No factory defined for #{inspect(factory_name)}. + + Please check for typos or define your factory: + + def #{factory_name}_factory do + ... + end + """ + + %__MODULE__{message: message} + end +end diff --git a/mix.lock b/mix.lock index 287f99c..0e1f4c6 100644 --- a/mix.lock +++ b/mix.lock @@ -1,10 +1,8 @@ %{ - "benchee": {:hex, :benchee, "1.3.0", "f64e3b64ad3563fa9838146ddefb2d2f94cf5b473bdfd63f5ca4d0657bf96694", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "34f4294068c11b2bd2ebf2c59aac9c7da26ffa0068afdf3419f1b176e16c5f81"}, "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"}, "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, - "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, "doctor": {:hex, :doctor, "0.21.0", "20ef89355c67778e206225fe74913e96141c4d001cb04efdeba1a2a9704f1ab5", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a227831daa79784eb24cdeedfa403c46a4cb7d0eab0e31232ec654314447e4e0"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, @@ -20,6 +18,5 @@ "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "postgrex": {:hex, :postgrex, "0.17.4", "5777781f80f53b7c431a001c8dad83ee167bcebcf3a793e3906efff680ab62b3", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "6458f7d5b70652bc81c3ea759f91736c16a31be000f306d3c64bcdfe9a18b3cc"}, - "statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, } diff --git a/test/ex_machina/ecto_strategy_test.exs b/test/ex_machina/ecto_strategy_test.exs index d8888eb..35b712d 100644 --- a/test/ex_machina/ecto_strategy_test.exs +++ b/test/ex_machina/ecto_strategy_test.exs @@ -133,7 +133,7 @@ defmodule ExMachina.EctoStrategyTest do refute Enum.member?(publisher_fields, :name) - publisher = Map.merge(TestFactory.build(:publisher), %{name: "name"}) + publisher = :publisher |> TestFactory.build() |> Map.merge(%{name: "name"}) model = TestFactory.insert(:article, publisher: publisher) assert model.publisher.name == "name" @@ -157,11 +157,11 @@ defmodule ExMachina.EctoStrategyTest do assert without_args.id assert without_args.db_value - with_struct = TestFactory.build(:user) |> TestFactory.insert(returning: true) + with_struct = :user |> TestFactory.build() |> TestFactory.insert(returning: true) assert with_struct.id assert with_struct.db_value - without_opts = TestFactory.build(:user) |> TestFactory.insert() + without_opts = :user |> TestFactory.build() |> TestFactory.insert() assert without_opts.id refute without_opts.db_value end @@ -200,7 +200,7 @@ defmodule ExMachina.EctoStrategyTest do message = ~r/You called `insert` on a record that has already been inserted./ assert_raise RuntimeError, message, fn -> - TestFactory.insert(:user, name: "Maximus") |> TestFactory.insert() + :user |> TestFactory.insert(name: "Maximus") |> TestFactory.insert() end end end diff --git a/test/ex_machina/ecto_test.exs b/test/ex_machina/ecto_test.exs index b58e126..3ddccf4 100644 --- a/test/ex_machina/ecto_test.exs +++ b/test/ex_machina/ecto_test.exs @@ -53,7 +53,7 @@ defmodule ExMachina.EctoTest do describe "insert/2 insert_pair/2 insert_list/3" do test "insert, insert_pair and insert_list inserts records" do - assert %User{} = TestFactory.build(:user) |> TestFactory.insert() + assert %User{} = :user |> TestFactory.build() |> TestFactory.insert() assert %User{} = TestFactory.insert(:user) assert %User{} = TestFactory.insert(:user, admin: true) @@ -324,6 +324,6 @@ defmodule ExMachina.EctoTest do end defp has_association_in_schema?(model, association_name) do - Enum.member?(model.__schema__(:associations), association_name) + :associations |> model.__schema__() |> Enum.member?(association_name) end end diff --git a/test/ex_machina/strategy_test.exs b/test/ex_machina/strategy_test.exs index b11e18b..4cf5668 100644 --- a/test/ex_machina/strategy_test.exs +++ b/test/ex_machina/strategy_test.exs @@ -34,7 +34,7 @@ defmodule ExMachina.StrategyTest do strategy_options = %{foo: :bar, factory_module: JsonFactory} function_options = [encode: true] - JsonFactory.build(:user) |> JsonFactory.json_encode() + :user |> JsonFactory.build() |> JsonFactory.json_encode() built_user = JsonFactory.build(:user) assert_received {:handle_json_encode, ^built_user, ^strategy_options} refute_received {:handle_json_encode, _, _} diff --git a/test/support/models/invalid_type.ex b/test/support/models/invalid_type.ex index 30989fa..29bbfef 100644 --- a/test/support/models/invalid_type.ex +++ b/test/support/models/invalid_type.ex @@ -2,6 +2,8 @@ defmodule ExMachina.InvalidType do @behaviour Ecto.Type def type, do: :integer + def equal?(_a, _b), do: false + def embed_as(_), do: :self def cast(_), do: :error def load(_), do: :error From c809bce0db914604b431be8d47d922aae9fe8e3e Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Thu, 18 Jan 2024 15:52:28 -0500 Subject: [PATCH 13/25] chore: sync files with beam-community/common-config (#441) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/ci.yaml | 15 +++++++++++++++ .github/workflows/production.yaml | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bebad11..505692a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -84,6 +84,8 @@ jobs: run: mix format --check-formatted Test: + name: Test (Elixir ${{ matrix.versions.elixir }} OTP ${{ matrix.versions.otp }}) + runs-on: ubuntu-latest env: @@ -106,7 +108,9 @@ jobs: - name: Setup Elixir uses: stordco/actions-elixir/setup@v1 with: + elixir-version: ${{ matrix.versions.elixir }} github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + otp-version: ${{ matrix.versions.otp }} - name: Compile run: mix compile --warnings-as-errors @@ -114,3 +118,14 @@ jobs: - name: Test run: mix test + strategy: + fail-fast: false + matrix: + versions: + - elixir: 1.13 + otp: 25 + - elixir: 1.14 + otp: 25 + - elixir: 1.15 + otp: 26 + diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index 2a6b98f..6304a1e 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/production.yaml @@ -13,3 +13,23 @@ concurrency: group: Production jobs: + Hex: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + + - name: Compile + run: mix compile --docs + + - name: Publish + run: mix hex.publish --yes + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} + From ae31578057b682b6bf7d51d3bb29229e4cbb16c3 Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Thu, 18 Jan 2024 13:54:15 -0700 Subject: [PATCH 14/25] chore: add release please manifest file --- .github/release-please-manifest.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/release-please-manifest.json diff --git a/.github/release-please-manifest.json b/.github/release-please-manifest.json new file mode 100644 index 0000000..6ed9c80 --- /dev/null +++ b/.github/release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "2.7.0" +} From 6aab2c80cf17a66a0f087e6402b74e5477510884 Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Thu, 18 Jan 2024 13:59:14 -0700 Subject: [PATCH 15/25] chore: update test postgres configuration --- config/test.exs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/test.exs b/config/test.exs index 02efe67..cde4a60 100644 --- a/config/test.exs +++ b/config/test.exs @@ -3,9 +3,11 @@ import Config config :ex_machina, preserve_dates: true config :ex_machina, ExMachina.TestRepo, - hostname: "localhost", - database: "ex_machina_test", pool: Ecto.Adapters.SQL.Sandbox, - username: "postgres" + hostname: "localhost", + port: "5432" + username: "postgres", + password: "postgres", + database: "ex_machina_test" config :logger, level: :warning From cf74a91a4f0b913b6b96a233692419a030be4cff Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Thu, 18 Jan 2024 14:00:15 -0700 Subject: [PATCH 16/25] chore: fix missing , in configuration file --- config/test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/test.exs b/config/test.exs index cde4a60..7b5d858 100644 --- a/config/test.exs +++ b/config/test.exs @@ -5,7 +5,7 @@ config :ex_machina, preserve_dates: true config :ex_machina, ExMachina.TestRepo, pool: Ecto.Adapters.SQL.Sandbox, hostname: "localhost", - port: "5432" + port: "5432",g username: "postgres", password: "postgres", database: "ex_machina_test" From e8edf473c84ba414c5c07c267abac773cb64be6d Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Thu, 18 Jan 2024 14:02:30 -0700 Subject: [PATCH 17/25] chore: remove extra character from test configuration file --- config/test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/test.exs b/config/test.exs index 7b5d858..d5bf44d 100644 --- a/config/test.exs +++ b/config/test.exs @@ -5,7 +5,7 @@ config :ex_machina, preserve_dates: true config :ex_machina, ExMachina.TestRepo, pool: Ecto.Adapters.SQL.Sandbox, hostname: "localhost", - port: "5432",g + port: "5432", username: "postgres", password: "postgres", database: "ex_machina_test" From c9ebb47d7ffecdae3acf22f71c257de8bcdcffdc Mon Sep 17 00:00:00 2001 From: Andrew Ruder Date: Thu, 18 Jan 2024 15:32:39 -0600 Subject: [PATCH 18/25] feat: ExMachina.start/2: return a supervisor from Application callback (#434) We're actually returning the PID for an Agent rather than a supervisor. In addition to being against the erlang callback spec: The function is to return {ok,Pid} or {ok,Pid,State}, where Pid is the pid of the top supervisor and State is any term. If omitted, State defaults to []. If the application is stopped later, State is passed to Module:prep_stop/1. Some tools like phoenix live dashboard will send the application supervisor supervisor-y messages and end up crashing the root application tree. ** (FunctionClauseError) no function clause matching in Agent.Server.handle_call/3 (elixir 1.14.5) lib/agent/server.ex:11: Agent.Server.handle_call(:which_children, {#PID<0.22073.22>, #Reference<0.3953567925.3593732098.137638>}, %{}) (stdlib 3.17) gen_server.erl:721: :gen_server.try_handle_call/4 (stdlib 3.17) gen_server.erl:750: :gen_server.handle_msg/6 (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3 Last message (from #PID<0.22073.22>): :which_children This change makes ExMachina return a supervisor with a single child - the ExMachina.Sequence. Have also moved to `use Agent` to get the child_spec/1 for free in ExMachina.Sequence. This has been tested per the tool versions file (1.7.4 + otp 21). --- lib/ex_machina.ex | 7 ++++++- lib/ex_machina/sequence.ex | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ex_machina.ex b/lib/ex_machina.ex index 04be659..a0b4fd0 100644 --- a/lib/ex_machina.ex +++ b/lib/ex_machina.ex @@ -16,7 +16,12 @@ defmodule ExMachina do @callback build_pair(factory_name :: atom, attrs :: keyword | map) :: list @doc false - def start(_type, _args), do: ExMachina.Sequence.start_link() + def start(_type, _args) do + Supervisor.start_link([ExMachina.Sequence], + strategy: :one_for_one, + name: __MODULE__.Supervisor + ) + end defmacro __using__(_opts) do quote do diff --git a/lib/ex_machina/sequence.ex b/lib/ex_machina/sequence.ex index 2268159..bbbbeb8 100644 --- a/lib/ex_machina/sequence.ex +++ b/lib/ex_machina/sequence.ex @@ -6,8 +6,10 @@ defmodule ExMachina.Sequence do sequential values instead of calling this module directly. """ + use Agent + @doc false - def start_link do + def start_link(_) do Agent.start_link(fn -> Map.new() end, name: __MODULE__) end From b796311761413086dac24dd3451ded8c0c349870 Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Tue, 21 May 2024 15:50:32 -0700 Subject: [PATCH 19/25] fix: revert code changes breaking ecto record loading (#447) * fix: revert code changes breaking ecto record loading * remove duplicate spec line --- lib/ex_machina/ecto.ex | 6 ++++-- lib/ex_machina/sequence.ex | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ex_machina/ecto.ex b/lib/ex_machina/ecto.ex index 7a1bded..0efb9e5 100644 --- a/lib/ex_machina/ecto.ex +++ b/lib/ex_machina/ecto.ex @@ -276,9 +276,11 @@ defmodule ExMachina.Ecto do association = struct.__schema__(:association, association_name) with %{__struct__: Ecto.Association.BelongsTo} <- association, - %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} = belongs_to <- - Map.get(record, association_name) do + belongs_to <- Map.get(record, association_name), + %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} <- belongs_to do set_belongs_to_primary_key(record, belongs_to, association) + else + _ -> record end end) end diff --git a/lib/ex_machina/sequence.ex b/lib/ex_machina/sequence.ex index bbbbeb8..10a3c17 100644 --- a/lib/ex_machina/sequence.ex +++ b/lib/ex_machina/sequence.ex @@ -77,14 +77,13 @@ defmodule ExMachina.Sequence do ExMachina.Sequence.next("joe") # "joe0" """ - @spec reset(list()) :: :ok + @spec reset(any()) :: :ok def reset(sequence_names) when is_list(sequence_names) do Agent.update(__MODULE__, fn sequences -> Enum.reduce(sequence_names, sequences, &Map.put(&2, &1, 0)) end) end - @spec reset(any()) :: :ok def reset(sequence_name) do Agent.update(__MODULE__, fn sequences -> Map.put(sequences, sequence_name, 0) From 5b056897ec9c60627d82307340e52db8ad6a9c5b Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Tue, 21 May 2024 18:54:44 -0400 Subject: [PATCH 20/25] docs: update ex_docs to v0.32 (#446) --- LICENSE => LICENSE.md | 0 mix.exs | 2 +- mix.lock | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) rename LICENSE => LICENSE.md (100%) diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/mix.exs b/mix.exs index 6a1298d..875a582 100644 --- a/mix.exs +++ b/mix.exs @@ -40,7 +40,7 @@ defmodule ExMachina.Mixfile do {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, {:doctor, "~> 0.21.0", only: [:dev, :test], runtime: false}, {:excoveralls, "~> 0.17.1", only: :test}, - {:ex_doc, "~> 0.28", only: [:dev, :test], runtime: false}, + {:ex_doc, "~> 0.32", only: [:dev, :test], runtime: false}, {:postgrex, "~> 0.17", only: :test} ] end diff --git a/mix.lock b/mix.lock index 0e1f4c6..7e4323e 100644 --- a/mix.lock +++ b/mix.lock @@ -9,13 +9,13 @@ "ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"}, "ecto_sql": {:hex, :ecto_sql, "3.11.1", "e9abf28ae27ef3916b43545f9578b4750956ccea444853606472089e7d169470", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ce14063ab3514424276e7e360108ad6c2308f6d88164a076aac8a387e1fea634"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"}, + "ex_doc": {:hex, :ex_doc, "0.32.2", "f60bbeb6ccbe75d005763e2a328e6f05e0624232f2393bc693611c2d3ae9fa0e", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "a4480305cdfe7fdfcbb77d1092c76161626d9a7aa4fb698aee745996e34602df"}, "excoveralls": {:hex, :excoveralls, "0.17.1", "83fa7906ef23aa7fc8ad7ee469c357a63b1b3d55dd701ff5b9ce1f72442b2874", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "95bc6fda953e84c60f14da4a198880336205464e75383ec0f570180567985ae0"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, - "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, + "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "postgrex": {:hex, :postgrex, "0.17.4", "5777781f80f53b7c431a001c8dad83ee167bcebcf3a793e3906efff680ab62b3", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "6458f7d5b70652bc81c3ea759f91736c16a31be000f306d3c64bcdfe9a18b3cc"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, From a4352dd59c3ce90d95fe85af65dda9ad332367d1 Mon Sep 17 00:00:00 2001 From: Sean Callan Date: Tue, 21 May 2024 19:02:05 -0400 Subject: [PATCH 21/25] chore: README updates (#444) * chore: README updates * add release please comments --------- Co-authored-by: Blake Kostner --- README.md | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 31ff12d..5e8babd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # ExMachina -[![Circle CI](https://circleci.com/gh/thoughtbot/ex_machina.svg?style=svg&circle-token=fea4685d4951936734e764796c4b37c3686cdab3)](https://circleci.com/gh/thoughtbot/ex_machina) - -**ExMachina is part of the [thoughtbot Elixir family][elixir-phoenix] of projects.** +[![Continuous Integration](https://github.com/beam-community/ex_machina/actions/workflows/ci.yaml/badge.svg)](https://github.com/beam-community/ex_machina/actions/workflows/ci.yaml) +[![Module Version](https://img.shields.io/hexpm/v/ex_machina.svg)](https://hex.pm/packages/ex_machina) +[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ex_machina/) +[![Total Download](https://img.shields.io/hexpm/dt/ex_machina.svg)](https://hex.pm/packages/ex_machina) +[![License](https://img.shields.io/hexpm/l/ex_machina.svg)](https://github.com/beam-community/ex_machina/blob/master/LICENSE) +[![Last Updated](https://img.shields.io/github/last-commit/beam-community/ex_machina.svg)](https://github.com/beam-community/ex_machina/commits/master) ExMachina makes it easy to create test data and associations. It works great with Ecto, but is configurable to work with any persistence library. @@ -12,34 +15,9 @@ with Ecto, but is configurable to work with any persistence library. ## Installation -#### To install in all environments (useful for generating seed data in dev/prod): - -In `mix.exs`, add the ExMachina dependency: - -```elixir -def deps do - # Get the latest from hex.pm. Works with Ecto 3.0 - [ - {:ex_machina, "~> 2.7.0"}, - ] -end -``` - -And start the ExMachina application. For most projects (such as -Phoenix apps) this will mean adding `:ex_machina` to the list of applications in -`mix.exs`. You can skip this step if you are using Elixir 1.4 or later. - -```elixir -def application do - [mod: {MyApp, []}, - applications: [:ex_machina, :other_apps...]] -end -``` - -#### Install in just the test environment with Phoenix: - In `mix.exs`, add the ExMachina dependency: + ```elixir def deps do [ @@ -47,6 +25,7 @@ def deps do ] end ``` + Add your factory module inside `test/support` so that it is only compiled in the test environment. @@ -58,7 +37,7 @@ ExUnit.start: {:ok, _} = Application.ensure_all_started(:ex_machina) ``` -#### Install in just the test environment for non-Phoenix projects: +#### Install in just the test environment for non-Phoenix projects You will follow the same instructions as above, but you will also need to add `test/support` to your compilation paths (elixirc_paths) if you have not done @@ -494,10 +473,10 @@ MyApp.Factory.json_encode(:user) Before opening a pull request, please open an issue first. - $ git clone https://github.com/thoughtbot/ex_machina.git - $ cd ex_machina - $ mix deps.get - $ mix test + git clone https://github.com/thoughtbot/ex_machina.git + cd ex_machina + mix deps.get + mix test Once you've made your additions and `mix test` passes, go ahead and open a PR! From 88c6450b0223f3a3ea95d309046ac090168d8555 Mon Sep 17 00:00:00 2001 From: Nathan Long Date: Mon, 24 Jun 2024 16:03:22 -0400 Subject: [PATCH 22/25] Document another way to build derived attributes (#449) --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e8babd..fe7ee5a 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,16 @@ defmodule MyApp.Factory do %MyApp.Article{ title: title, slug: slug, + # another way to build derived attributes + tags: fn article -> + if String.contains?(article.title, "Silly") do + ["silly"] + else + [] + end + end, # associations are inserted when you call `insert` - author: build(:user), + author: build(:user) } end From cca2acfecd66b1002eff2470a42e9302c76f5495 Mon Sep 17 00:00:00 2001 From: The BEAM Bot <157067248+thebeambot@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:07:13 -0400 Subject: [PATCH 23/25] chore: sync files with beam-community/common-config (#448) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 505692a..8888ddc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -122,10 +122,10 @@ jobs: fail-fast: false matrix: versions: - - elixir: 1.13 - otp: 25 - - elixir: 1.14 - otp: 25 - elixir: 1.15 otp: 26 + - elixir: 1.16 + otp: 26 + - elixir: 1.17 + otp: 27 From 69612ae19903a9410cc1fbaf9680d070c0b72370 Mon Sep 17 00:00:00 2001 From: The BEAM Bot <157067248+thebeambot@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:02:49 -0400 Subject: [PATCH 24/25] chore: sync files with beam-community/common-config (#450) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/CODEOWNERS | 4 ---- .github/workflows/pr.yaml | 10 +++++++++- .tool-versions | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b06a787..43b776a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1 @@ -# Order alphabetically. -# Order is important. The last matching pattern takes the most precedence. - -# Default owners for everything in the repo. * @beam-community/team diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5e2628a..f6036fe 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -21,7 +21,7 @@ jobs: - name: Check uses: stordco/actions-pr-title@v1.0.0 with: - regex: '^(feat!|fix!|fix|feat|chore)(\(\w+\))?:\s(\[#\d{1,5}\])?.*$' + regex: '^(refactor!|feat!|fix!|refactor|fix|feat|chore)(\(\w+\))?:\s(\[#\d{1,5}\])?.*$' hint: | Your PR title does not match the Conventional Commits convention. Please rename your PR to match one of the following formats: @@ -32,4 +32,12 @@ jobs: Note: Adding ! (i.e. `feat!:`) represents a breaking change and will result in a SemVer major release. + Please use one of the following types: + + - **feat:** A new feature, resulting in a MINOR version bump." + - **fix:** A bug fix, resulting in a PATCH version bump." + - **refactor:** A code change that neither fixes a bug nor adds a feature, resulting in a PATCH version bump." + - **chore:** Changes unrelated to the release code, resulting in no version bump." + - **revert:** Reverts a previous commit." + See https://www.conventionalcommits.org/en/v1.0.0/ for more information. diff --git a/.tool-versions b/.tool-versions index f14e1e3..fe29d91 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -elixir 1.15.4-otp-25 -erlang 25.3.2.5 +elixir 1.16 +erlang 26.0 From d1ec5e4b5af19276e2f5c184a05aa849323ad9a3 Mon Sep 17 00:00:00 2001 From: The BEAM Bot <157067248+thebeambot@users.noreply.github.com> Date: Tue, 25 Jun 2024 07:45:02 -0400 Subject: [PATCH 25/25] chore(main): release 2.8.0 (#443) --- .github/release-please-manifest.json | 2 +- CHANGELOG.md | 32 ++++++++++++++++++++++++++++ README.md | 2 +- mix.exs | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/release-please-manifest.json b/.github/release-please-manifest.json index 6ed9c80..7a56472 100644 --- a/.github/release-please-manifest.json +++ b/.github/release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.7.0" + ".": "2.8.0" } diff --git a/CHANGELOG.md b/CHANGELOG.md index f2d6f0c..ab9b6b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,38 @@ complete changelog, see the git history for each version via the version links. [hex package page]: https://hex.pm/packages/ex_machina +## [2.8.0](https://github.com/beam-community/ex_machina/compare/v2.7.0...v2.8.0) (2024-06-24) + + +### Features + +* ExMachina.start/2: return a supervisor from Application callback ([#434](https://github.com/beam-community/ex_machina/issues/434)) ([c9ebb47](https://github.com/beam-community/ex_machina/commit/c9ebb47d7ffecdae3acf22f71c257de8bcdcffdc)) + + +### Bug Fixes + +* Revert code changes breaking ecto record loading ([#447](https://github.com/beam-community/ex_machina/issues/447)) ([b796311](https://github.com/beam-community/ex_machina/commit/b796311761413086dac24dd3451ded8c0c349870)) + + +### Miscellaneous + +* Add release please manifest file ([ae31578](https://github.com/beam-community/ex_machina/commit/ae31578057b682b6bf7d51d3bb29229e4cbb16c3)) +* Clear up log level warning ([821a61a](https://github.com/beam-community/ex_machina/commit/821a61a351676c2fee717451d8881059dc04730d)) +* Fix missing , in configuration file ([cf74a91](https://github.com/beam-community/ex_machina/commit/cf74a91a4f0b913b6b96a233692419a030be4cff)) +* README updates ([#444](https://github.com/beam-community/ex_machina/issues/444)) ([a4352dd](https://github.com/beam-community/ex_machina/commit/a4352dd59c3ce90d95fe85af65dda9ad332367d1)) +* Remove circleci, update tools-version ([#438](https://github.com/beam-community/ex_machina/issues/438)) ([b06f4b6](https://github.com/beam-community/ex_machina/commit/b06f4b6ebe323b8c0b4edcc961fbf4abb5a68bcd)) +* Remove extra character from test configuration file ([e8edf47](https://github.com/beam-community/ex_machina/commit/e8edf473c84ba414c5c07c267abac773cb64be6d)) +* Resolve config warning ([#440](https://github.com/beam-community/ex_machina/issues/440)) ([a327830](https://github.com/beam-community/ex_machina/commit/a32783031b21cd91bced561d4a30e9031f8a77e9)) +* Satisfy Credo consistency check ([5aa4f01](https://github.com/beam-community/ex_machina/commit/5aa4f01c8234a76cb3a41fa43e6da7cbd668ba03)) +* Support common-config ([#436](https://github.com/beam-community/ex_machina/issues/436)) ([2c2a309](https://github.com/beam-community/ex_machina/commit/2c2a309532f418083dac0df7bc74bf675056ad28)) +* Sync files with beam-community/common-config ([#437](https://github.com/beam-community/ex_machina/issues/437)) ([72e4038](https://github.com/beam-community/ex_machina/commit/72e40389a273a38be5f8dd96aef02976258212aa)) +* Sync files with beam-community/common-config ([#441](https://github.com/beam-community/ex_machina/issues/441)) ([c809bce](https://github.com/beam-community/ex_machina/commit/c809bce0db914604b431be8d47d922aae9fe8e3e)) +* Sync files with beam-community/common-config ([#448](https://github.com/beam-community/ex_machina/issues/448)) ([cca2acf](https://github.com/beam-community/ex_machina/commit/cca2acfecd66b1002eff2470a42e9302c76f5495)) +* Sync files with beam-community/common-config ([#450](https://github.com/beam-community/ex_machina/issues/450)) ([69612ae](https://github.com/beam-community/ex_machina/commit/69612ae19903a9410cc1fbaf9680d070c0b72370)) +* Update and run formatter ([#439](https://github.com/beam-community/ex_machina/issues/439)) ([8bb6057](https://github.com/beam-community/ex_machina/commit/8bb605725658a9dc36bd6e1f1579736f4b6514f4)) +* Update mix.exs and deps ([c6c76f0](https://github.com/beam-community/ex_machina/commit/c6c76f044d4fe8f57d82daed50800f8d43bd15b2)) +* Update test postgres configuration ([6aab2c8](https://github.com/beam-community/ex_machina/commit/6aab2c80cf17a66a0f087e6402b74e5477510884)) + ## [2.7.0] [2.7.0]: https://github.com/thoughtbot/ex_machina/compare/v2.6.0...v2.7.0 diff --git a/README.md b/README.md index fe7ee5a..dfae9ce 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ In `mix.exs`, add the ExMachina dependency: ```elixir def deps do [ - {:ex_machina, "~> 2.7.0", only: :test}, + {:ex_machina, "~> 2.8.0", only: :test}, ] end ``` diff --git a/mix.exs b/mix.exs index 875a582..0753c06 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule ExMachina.Mixfile do [ app: :ex_machina, description: "A factory library by the creators of FactoryBot (née FactoryGirl)", - version: "2.7.0", + version: "2.8.0", elixir: "~> 1.11", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod,