Skip to content

Commit

Permalink
person test added
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 16, 2016
1 parent bf290b5 commit 6875067
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/.iex.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Ecto.Query
64 changes: 63 additions & 1 deletion example/test/person_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
defmodule PersonTest do
use ExUnit.Case
import Ecto.Query

doctest Person

test "creating a person creates a person version with correct attributes" do
setup_all do
Repo.delete_all(Company)
Repo.delete_all(PaperTrail.Version)

Company.changeset(%Company{}, %{
name: "Acme LLC",
website: "http://www.acme.com"
}) |> Repo.insert

Company.changeset(%Company{}, %{
name: "Another Company Corp.",
is_active: true,
address: "Sesame street 100/3, 101010"
}) |> Repo.insert

:ok
end

test "creating a person with meta tag creates a person version with correct attributes" do
company = first(Company, :id) |> Repo.one

new_person = Person.changeset(%Person{}, %{
first_name: "Izel",
last_name: "Nakri",
gender: true,
company_id: company.id
})

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

person_count = Repo.all(
from person in Person,
select: count(person.id)
)

person = result[:model] |> Map.drop([:__meta__, :__struct__, :inserted_at, :updated_at, :id])

version_count = Repo.all(
from version in PaperTrail.Version,
select: count(version.id)
)

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

assert person_count == [1]
assert version_count == [1]

assert person == %{
first_name: "Izel",
last_name: "Nakri",
gender: true,
visit_count: nil,
birthdate: nil
}

assert Map.drop(version, [:id]) == %{
event: "create",
item_type: "Person",
item_id: Repo.one(first(Person, :id)).id,
item_changes: Map.drop(result[:model], [:__meta__, :__struct__]),
meta: nil
}
end

test "updating a person creates a person version with correct attributes" do
Expand Down

0 comments on commit 6875067

Please sign in to comment.