Skip to content

Commit

Permalink
update tests, #30
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Feb 5, 2019
1 parent 400fef0 commit 530f7e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions test/all_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ defmodule AlogTest.AllTest do
test "does not include old items" do
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert()
{:ok, _} = %User{} |> User.changeset(Helpers.user_2_params()) |> User.insert()
{:ok, user_updated} = user |> User.changeset(%{postcode: "W2 3EC"}) |> User.update()
{:ok, _} = user |> User.changeset(%{postcode: "W2 3EC"}) |> User.update()

assert length(User.all()) == 2
assert user.inserted_at == user_updated.inserted_at
end

test "all return inserted_at original value" do
{:ok, user} = %User{} |> User.changeset(Helpers.user_3_params()) |> User.insert()
{:ok, user_updated} = user |> User.changeset(%{postcode: "W2 3EC"}) |> User.update()

[user_all] = User.all()
assert user_all.inserted_at == user.inserted_at
assert user_all.postcode == user_updated.postcode
end
end
end
4 changes: 2 additions & 2 deletions test/get_by_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule AlogTest.GetByTest do

test "does not retrieve outdated results" do
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert()
{:ok, updated_user} = user |> User.changeset(%{postcode: "EC3 RST"}) |> User.update()
{:ok, _updated_user} = user |> User.changeset(%{postcode: "EC3 RST"}) |> User.update()

assert User.get_by(postcode: "E2 0SY") == nil
end
Expand All @@ -58,7 +58,7 @@ defmodule AlogTest.GetByTest do
|> User.changeset(Map.put(Helpers.user_2_params(), :postcode, "E2 0SY"))
|> User.insert()

{:ok, updated_user_2} = user_2 |> User.changeset(%{postcode: "EC3 RST"}) |> User.update()
{:ok, _} = user_2 |> User.changeset(%{postcode: "EC3 RST"}) |> User.update()

assert User.get_by(postcode: "E2 0SY") == user
end
Expand Down
2 changes: 2 additions & 0 deletions test/support/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule Alog.TestApp.Helpers do

def user_2_params(), do: %{name: "Loki", username: "mschfmkr", postcode: "E1 6DR"}

def user_3_params(), do: %{name: "Bob", username: "bobuser", postcode: "E1 7DR"}

def seed_data() do
{:ok, item_type} = %ItemType{} |> ItemType.changeset(%{type: "Weapon"}) |> ItemType.insert()

Expand Down

0 comments on commit 530f7e0

Please sign in to comment.