From 9852dc3ee2e567510a88f8d0694c58f324c27ec4 Mon Sep 17 00:00:00 2001 From: Izel Nakri Date: Sun, 19 Mar 2017 17:44:55 +0100 Subject: [PATCH] example tests are fixed --- example/mix.exs | 6 +++--- example/mix.lock | 14 +++++++------- .../migrations/20160715113439_create_companies.exs | 2 +- .../migrations/20160715113442_create_people.exs | 2 +- .../migrations/20160715134921_add_versions.exs | 6 +++++- example/test/company_test.exs | 8 +++++++- example/test/person_test.exs | 14 +++++++++----- 7 files changed, 33 insertions(+), 19 deletions(-) diff --git a/example/mix.exs b/example/mix.exs index ec5ec896..29dfadce 100644 --- a/example/mix.exs +++ b/example/mix.exs @@ -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 diff --git a/example/mix.lock b/example/mix.lock index 6cce6261..fe40fc77 100644 --- a/example/mix.lock +++ b/example/mix.lock @@ -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]}]}} diff --git a/example/priv/repo/migrations/20160715113439_create_companies.exs b/example/priv/repo/migrations/20160715113439_create_companies.exs index 3e00221e..37fe63ea 100644 --- a/example/priv/repo/migrations/20160715113439_create_companies.exs +++ b/example/priv/repo/migrations/20160715113439_create_companies.exs @@ -12,7 +12,7 @@ defmodule Example.Repo.Migrations.CreateCompanies do add :twitter, :string add :founded_in, :string - timestamps + timestamps() end end end diff --git a/example/priv/repo/migrations/20160715113442_create_people.exs b/example/priv/repo/migrations/20160715113442_create_people.exs index c7cdd4c8..30e2262d 100644 --- a/example/priv/repo/migrations/20160715113442_create_people.exs +++ b/example/priv/repo/migrations/20160715113442_create_people.exs @@ -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]) diff --git a/example/priv/repo/migrations/20160715134921_add_versions.exs b/example/priv/repo/migrations/20160715134921_add_versions.exs index d213ef48..085b640f 100644 --- a/example/priv/repo/migrations/20160715134921_add_versions.exs +++ b/example/priv/repo/migrations/20160715134921_add_versions.exs @@ -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 diff --git a/example/test/company_test.exs b/example/test/company_test.exs index 9382703c..15370a37 100644 --- a/example/test/company_test.exs +++ b/example/test/company_test.exs @@ -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, @@ -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 @@ -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 @@ -155,6 +159,8 @@ defmodule CompanyTest do twitter: nil, founded_in: nil }, + origin: nil, + originator_id: nil, meta: nil } end diff --git a/example/test/person_test.exs b/example/test/person_test.exs index 8a618363..c24d52bf 100644 --- a/example/test/person_test.exs +++ b/example/test/person_test.exs @@ -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, @@ -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 @@ -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" }) @@ -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" } } @@ -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