From 7c4047233252b6b33f7a523fdf594692f616aa72 Mon Sep 17 00:00:00 2001 From: Izel Nakri Date: Thu, 27 Feb 2020 23:10:20 +0100 Subject: [PATCH] mix format run --- lib/paper_trail.ex | 1 + lib/paper_trail/multi.ex | 18 +++++++++++++++--- test/paper_trail/paper_trail_version_test.exs | 12 ++++++++---- test/paper_trail/uuid_test.exs | 10 ++++++++-- test/paper_trail/version_queries_test.exs | 4 +++- test/support/multi_tenant_helper.exs | 2 +- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/paper_trail.ex b/lib/paper_trail.ex index 73a8aac6..dd281f80 100644 --- a/lib/paper_trail.ex +++ b/lib/paper_trail.ex @@ -236,6 +236,7 @@ defmodule PaperTrail do case PaperTrail.Version.__schema__(:type, :item_id) do :integer -> model_id + _ -> "#{model_id}" end diff --git a/lib/paper_trail/multi.ex b/lib/paper_trail/multi.ex index f2a2c0f0..c25bc836 100644 --- a/lib/paper_trail/multi.ex +++ b/lib/paper_trail/multi.ex @@ -15,7 +15,11 @@ defmodule PaperTrail.Multi do defdelegate run(multi, name, mod, fun, args), to: Ecto.Multi defdelegate to_list(multi), to: Ecto.Multi - def insert(%Ecto.Multi{} = multi, changeset, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do + def insert( + %Ecto.Multi{} = multi, + changeset, + options \\ [origin: nil, meta: nil, originator: nil, prefix: nil] + ) do case RepoClient.strict_mode() do true -> multi @@ -59,7 +63,11 @@ defmodule PaperTrail.Multi do end end - def update(%Ecto.Multi{} = multi, changeset, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do + def update( + %Ecto.Multi{} = multi, + changeset, + options \\ [origin: nil, meta: nil, originator: nil, prefix: nil] + ) do case RepoClient.strict_mode() do true -> multi @@ -98,7 +106,11 @@ defmodule PaperTrail.Multi do end end - def delete(%Ecto.Multi{} = multi, struct, options \\ [origin: nil, meta: nil, originator: nil, prefix: nil]) do + def delete( + %Ecto.Multi{} = multi, + struct, + options \\ [origin: nil, meta: nil, originator: nil, prefix: nil] + ) do multi |> Ecto.Multi.delete(:model, struct, options) |> Ecto.Multi.run(:version, fn repo, %{} -> diff --git a/test/paper_trail/paper_trail_version_test.exs b/test/paper_trail/paper_trail_version_test.exs index 06859e72..730740fb 100644 --- a/test/paper_trail/paper_trail_version_test.exs +++ b/test/paper_trail/paper_trail_version_test.exs @@ -62,13 +62,15 @@ defmodule PaperTrailTest.Version do add_three_versions() target_model = - @valid_attrs |> Map.delete(:inserted_at) + @valid_attrs + |> Map.delete(:inserted_at) |> Map.merge(%{ item_changes: %{"first_name" => "Izel", "last_name" => "Nakri"} }) target_version = - Version.first() |> serialize + Version.first() + |> serialize |> Map.drop([ :id, :meta, @@ -103,7 +105,8 @@ defmodule PaperTrailTest.Version do add_three_versions(MultiTenant.tenant()) target_version = - Version.first(prefix: MultiTenant.tenant()) |> serialize + Version.first(prefix: MultiTenant.tenant()) + |> serialize |> Map.drop([ :id, :meta, @@ -112,7 +115,8 @@ defmodule PaperTrailTest.Version do ]) target_model = - @valid_attrs |> Map.delete(:inserted_at) + @valid_attrs + |> Map.delete(:inserted_at) |> Map.merge(%{ item_changes: %{"first_name" => "Izel", "last_name" => "Nakri"} }) diff --git a/test/paper_trail/uuid_test.exs b/test/paper_trail/uuid_test.exs index b9629090..56410fc7 100644 --- a/test/paper_trail/uuid_test.exs +++ b/test/paper_trail/uuid_test.exs @@ -8,7 +8,13 @@ defmodule PaperTrailTest.UUIDTest do Application.put_env(:paper_trail, :repo, PaperTrail.UUIDRepo) Application.put_env(:paper_trail, :originator, name: :admin, model: Admin) Application.put_env(:paper_trail, :originator_type, Ecto.UUID) - Application.put_env(:paper_trail, :item_type, (if System.get_env("STRING_TEST") == nil, do: Ecto.UUID, else: :string)) + + Application.put_env( + :paper_trail, + :item_type, + if(System.get_env("STRING_TEST") == nil, do: Ecto.UUID, else: :string) + ) + Code.eval_file("lib/paper_trail.ex") Code.eval_file("lib/version.ex") repo().delete_all(Version) @@ -75,7 +81,7 @@ defmodule PaperTrailTest.UUIDTest do if PaperTrail.Version.__schema__(:type, :item_id) == :string do item = %BarItem{} - |> BarItem.changeset(%{item_id: "#{:os.system_time}", title: "hello"}) + |> BarItem.changeset(%{item_id: "#{:os.system_time()}", title: "hello"}) |> PaperTrail.insert!() version = Version |> last |> repo().one diff --git a/test/paper_trail/version_queries_test.exs b/test/paper_trail/version_queries_test.exs index f2b825c2..55d1c0ed 100644 --- a/test/paper_trail/version_queries_test.exs +++ b/test/paper_trail/version_queries_test.exs @@ -163,7 +163,9 @@ defmodule PaperTrailTest.VersionQueries do person = first(Person, :id) |> @repo.one first_version = - Version |> where([v], v.item_type == "SimplePerson" and v.item_id == ^person.id) |> first + Version + |> where([v], v.item_type == "SimplePerson" and v.item_id == ^person.id) + |> first |> @repo.one assert PaperTrail.get_current_model(first_version) == person diff --git a/test/support/multi_tenant_helper.exs b/test/support/multi_tenant_helper.exs index 5479159c..9f8c7a41 100644 --- a/test/support/multi_tenant_helper.exs +++ b/test/support/multi_tenant_helper.exs @@ -33,7 +33,7 @@ defmodule PaperTrailTest.MultiTenantHelper do defp migrations_path(repo), do: Path.join(build_repo_priv(repo), @migrations_path) def source_repo_priv(repo) do - repo.config()[:priv] || "priv/#{repo |> Module.split |> List.last |> Macro.underscore}" + repo.config()[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}" end def build_repo_priv(repo) do