Skip to content

Commit

Permalink
example tests are fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Mar 19, 2017
1 parent c0cdd38 commit 9852dc3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
6 changes: 3 additions & 3 deletions example/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ defmodule Example.Mixfile do
defp deps do
[
{:postgrex, ">= 0.0.0"},
{:ecto, "~> 2.0.2"},
{:poison, "2.1.0"},
{:paper_trail, ">= 0.0.0"}
{:ecto, ">= 2.0.2"},
{:poison, ">= 2.1.0"},
{:paper_trail, ">= 0.7.3"}
]
end
end
14 changes: 7 additions & 7 deletions example/mix.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%{"connection": {:hex, :connection, "1.0.3", "3145f7416be3df248a4935f24e3221dc467c1e3a158d62015b35bd54da365786", [:mix], []},
"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.1.0", "0ebc0159795bb8d99b1633a552312a947b80f88f48d338ff02f1ba445fd3605e", [: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], []},
%{"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []},
"db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], []},
"ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"paper_trail": {:hex, :paper_trail, "0.7.3", "2e65a18c0928264c2e18dccdba7794b847c90a20cfa3a2fd1e2668d7690452d3", [:mix], [{:ecto, ">= 2.1.0", [hex: :ecto, optional: false]}, {:poison, ">= 3.1.0 or >= 2.0.0", [hex: :poison, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: false]}]},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [: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]}]}}
"postgrex": {:hex, :postgrex, "0.13.2", "2b88168fc6a5456a27bfb54ccf0ba4025d274841a7a3af5e5deb1b755d95154e", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Example.Repo.Migrations.CreateCompanies do
add :twitter, :string
add :founded_in, :string

timestamps
timestamps()
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Example.Repo.Migrations.CreatePeople do

add :company_id, references(:companies), null: false

timestamps
timestamps()
end

create index(:people, [:company_id])
Expand Down
6 changes: 5 additions & 1 deletion example/priv/repo/migrations/20160715134921_add_versions.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ defmodule Repo.Migrations.AddVersions do
add :item_type, :string
add :item_id, :integer
add :item_changes, :map
add :origin, :string
add :originator_id, references(:people)
add :meta, :map

add :inserted_at, :datetime, null: false
add :inserted_at, :utc_datetime, null: false
end

create index(:versions, [:originator_id])
end
end
8 changes: 7 additions & 1 deletion example/test/company_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule CompanyTest do
name: "Acme LLC", is_active: true, city: "Greenwich", people: []
})

{:ok, result} = PaperTrail.insert(new_company)
{:ok, result} = PaperTrail.insert(new_company, origin: "test")

company_count = Repo.all(
from company in Company,
Expand Down Expand Up @@ -52,6 +52,8 @@ defmodule CompanyTest do
item_type: "Company",
item_id: Repo.one(first(Company, :id)).id,
item_changes: Map.drop(result[:model], [:__meta__, :__struct__, :people]),
origin: "test",
originator_id: nil,
meta: nil
}
end
Expand Down Expand Up @@ -100,6 +102,8 @@ defmodule CompanyTest do
item_type: "Company",
item_id: Repo.one(first(Company, :id)).id,
item_changes: %{city: "Hong Kong", website: "http://www.acme.com", facebook: "acme.llc"},
origin: nil,
originator_id: nil,
meta: nil
}
end
Expand Down Expand Up @@ -155,6 +159,8 @@ defmodule CompanyTest do
twitter: nil,
founded_in: nil
},
origin: nil,
originator_id: nil,
meta: nil
}
end
Expand Down
14 changes: 9 additions & 5 deletions example/test/person_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule PersonTest do
company_id: company.id
})

{:ok, result} = PaperTrail.insert(new_person, %{originator: "admin"}) # add link name later on
{:ok, result} = PaperTrail.insert(new_person, origin: "admin", meta: %{}) # add link name later on

person_count = Repo.all(
from person in Person,
Expand Down Expand Up @@ -66,7 +66,9 @@ defmodule PersonTest do
item_type: "Person",
item_id: Repo.one(first(Person, :id)).id,
item_changes: Map.drop(result[:model], [:__meta__, :__struct__, :company]),
meta: %{originator: "admin"}
origin: "admin",
originator_id: nil,
meta: %{}
}
end

Expand All @@ -86,8 +88,7 @@ defmodule PersonTest do
company_id: target_company.id
})

{:ok, result} = PaperTrail.update(new_person, %{
originator: "user:1",
{:ok, result} = PaperTrail.update(new_person, origin: "user:1", meta: %{
linkname: "izelnakri"
})

Expand Down Expand Up @@ -127,8 +128,9 @@ defmodule PersonTest do
birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1),
company_id: target_company.id
},
origin: "user:1",
originator_id: nil,
meta: %{
originator: "user:1",
linkname: "izelnakri"
}
}
Expand Down Expand Up @@ -169,6 +171,8 @@ defmodule PersonTest do
birthdate: elem(Ecto.Date.cast(~D[1992-04-01]), 1),
company_id: person.company.id
},
origin: nil,
originator_id: nil,
meta: nil
}
end
Expand Down

0 comments on commit 9852dc3

Please sign in to comment.