Skip to content

Commit

Permalink
first very good test
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 15, 2016
1 parent f2f5d59 commit fadb54a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/lib/company.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Company do
end

@required_fields ~w()
@optional_fields ~w()
@optional_fields ~w(name is_active website city address facebook twitter founded_in)

def changeset(model, params \\ :empty) do
model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Example.Repo.Migrations.CreateCompanies do
def change do
create table(:companies) do
add :name, :string
add :is_active, :string
add :is_active, :boolean
add :website, :string
add :city, :string
add :address, :string
Expand Down
37 changes: 32 additions & 5 deletions example/test/company_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,46 @@ defmodule CompanyTest do
name: "Acme LLC", is_active: true, city: "Greenwich"
})

{:ok, persisted_company} = PaperTrail.insert(new_company)

persisted_company |> inspect |> IO.puts
{:ok, result} = PaperTrail.insert(new_company)

company_count = Repo.all(
from company in Company,
select: count(company.id)
)

company = 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 company_count == [1]

# assert Map.
assert version_count == [1]

assert company == %{
name: "Acme LLC",
is_active: true,
city: "Greenwich",
website: nil,
address: nil,
facebook: nil,
twitter: nil,
founded_in: nil
}

version |> inspect |> IO.puts

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

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

0 comments on commit fadb54a

Please sign in to comment.