Skip to content

Commit

Permalink
paper trail alpha version complete with example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 16, 2016
1 parent cdd6f87 commit c605bf5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion example/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]},
"decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []},
"ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]},
"paper_trail": {:hex, :paper_trail, "0.0.8", "9be51d594ebdc1a228ad3f3b5cbafcca5d5e8e8661eb44319fd011c510ef2628", [:mix], [{:poison, "2.1.0", [hex: :poison, optional: false]}, {:ecto, "~> 2.0.2", [hex: :ecto, optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, optional: false]}]},
"paper_trail": {:hex, :paper_trail, "0.0.9", "4e9342ee2bae6df9c80a2a3b5619e8df2a0113a545e5671d964ffa5dc9c37b69", [:mix], [{:poison, "2.1.0", [hex: :poison, optional: false]}, {:ecto, "~> 2.0.2", [hex: :ecto, optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, optional: false]}]},
"poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
"postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}
3 changes: 1 addition & 2 deletions example/test/company_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ defmodule CompanyTest do
address: nil,
facebook: "acme.llc",
twitter: nil,
founded_in: nil,
people: []
founded_in: nil
},
meta: nil
}
Expand Down
43 changes: 18 additions & 25 deletions example/test/person_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule PersonTest do
end

test "deleting a person creates a person version with correct attributes" do
person = first(Person, :id) |> Repo.one
person = first(Person, :id) |> preload(:company) |> Repo.one

{:ok, result} = PaperTrail.delete(person)

Expand All @@ -153,32 +153,25 @@ defmodule PersonTest do

version = result[:version] |> Map.drop([:__meta__, :__struct__, :inserted_at])

assert person_count == [1]
assert person_count == [0]
assert version_count == [3]

assert person_ref == %{

assert Map.drop(version, [:id]) == %{
event: "destroy",
item_type: "Person",
item_id: person.id,
item_changes: %{
id: person.id,
inserted_at: person.inserted_at,
updated_at: person.updated_at,
first_name: "Isaac",
last_name: "Nakri",
gender: true,
visit_count: 10,
birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1),
company_id: person.company.id
},
meta: nil
}

# assert Map.drop(version, [:id]) == %{
# event: "destroy",
# item_type: "Company",
# item_id: company.id,
# item_changes: %{
# id: company.id,
# inserted_at: company.inserted_at,
# updated_at: company.updated_at,
# name: "Acme LLC",
# is_active: true,
# website: "http://www.acme.com",
# city: "Hong Kong",
# address: nil,
# facebook: "acme.llc",
# twitter: nil,
# founded_in: nil,
# people: []
# },
# meta: nil
# }
end
end
6 changes: 0 additions & 6 deletions lib/paper_trail.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ defmodule PaperTrail do
end

defp make_version_struct(%{event: "create"}, model, meta) do
IO.puts "make_version_struct called"
filter_item_changes(model) |> inspect |> IO.puts
%Version{
event: "create",
item_type: model.__struct__ |> Module.split |> List.last,
Expand Down Expand Up @@ -105,11 +103,7 @@ defmodule PaperTrail do
Multi.new
|> Multi.delete(:model, struct)
|> Multi.run(:version, fn %{model: model} ->
IO.puts("model is :")
model |> inspect |> IO.puts
version = make_version_struct(%{event: "destroy"}, model, meta)
IO.puts "version is"
version |> inspect |> IO.puts
Repo.insert(version)
end)
|> Repo.transaction
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule PaperTrail.Mixfile do

def project do
[app: :paper_trail,
version: "0.0.9",
version: "0.1.0",
elixir: "~> 1.3",
description: description,
build_embedded: Mix.env == :prod,
Expand Down

0 comments on commit c605bf5

Please sign in to comment.