Skip to content

Commit

Permalink
mix format run
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Feb 27, 2020
1 parent 53c2d66 commit 7c40472
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/paper_trail.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ defmodule PaperTrail do
case PaperTrail.Version.__schema__(:type, :item_id) do
:integer ->
model_id

_ ->
"#{model_id}"
end
Expand Down
18 changes: 15 additions & 3 deletions lib/paper_trail/multi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, %{} ->
Expand Down
12 changes: 8 additions & 4 deletions test/paper_trail/paper_trail_version_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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"}
})
Expand Down
10 changes: 8 additions & 2 deletions test/paper_trail/uuid_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/paper_trail/version_queries_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/support/multi_tenant_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c40472

Please sign in to comment.