-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
did not delete for now as I thought we could use as a base
- Loading branch information
1 parent
8a3e176
commit f906baf
Showing
11 changed files
with
503 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
defmodule AlogTest.AllTest do | ||
use Alog.TestApp.DataCase | ||
|
||
alias Alog.TestApp.{User, Helpers} | ||
|
||
describe "all/0:" do | ||
test "succeeds" do | ||
{:ok, _} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
{:ok, _} = %User{} |> User.changeset(Helpers.user_2_params()) |> User.insert() | ||
|
||
assert length(User.all()) == 2 | ||
end | ||
|
||
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 |> User.changeset(%{postcode: "W2 3EC"}) |> User.update() | ||
|
||
assert length(User.all()) == 2 | ||
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 | ||
# alias Alog.TestApp.{User, Helpers} | ||
# | ||
# describe "all/0:" do | ||
# test "succeeds" do | ||
# {:ok, _} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# {:ok, _} = %User{} |> User.changeset(Helpers.user_2_params()) |> User.insert() | ||
# | ||
# assert length(User.all()) == 2 | ||
# end | ||
# | ||
# 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 |> User.changeset(%{postcode: "W2 3EC"}) |> User.update() | ||
# | ||
# assert length(User.all()) == 2 | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
defmodule AlogTest do | ||
use Alog.TestApp.DataCase | ||
doctest Alog | ||
|
||
describe "required fields" do | ||
test "schema without delete field raises error" do | ||
assert_raise RuntimeError, fn -> | ||
defmodule NoDeleteSchema do | ||
use Ecto.Schema | ||
use Alog | ||
|
||
schema "bad_schema" do | ||
field(:entry_id, :string) | ||
timestamps() | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "schema without entry_id field raises error" do | ||
assert_raise RuntimeError, fn -> | ||
defmodule NoEntrySchema do | ||
use Ecto.Schema | ||
use Alog | ||
|
||
schema "bad_schema" do | ||
field(:deleted, :boolean, default: false) | ||
timestamps() | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "schema with deleted field of wrong type raises error" do | ||
assert_raise RuntimeError, fn -> | ||
defmodule BadDeletedSchema do | ||
use Ecto.Schema | ||
use Alog | ||
|
||
schema "bad_schema" do | ||
field(:entry_id, :string) | ||
field(:deleted, :string) | ||
timestamps() | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "both required fields do not raise error" do | ||
assert (fn -> | ||
defmodule GoodSchema do | ||
use Ecto.Schema | ||
use Alog | ||
|
||
schema "bad_schema" do | ||
field(:entry_id, :string) | ||
field(:deleted, :boolean, default: false) | ||
timestamps() | ||
end | ||
end | ||
end).() | ||
end | ||
end | ||
|
||
describe "Not compatible with unique index" do | ||
test "Throws error if unique index exists" do | ||
assert_raise RuntimeError, fn -> | ||
%Alog.TestApp.Unique{} | ||
|> Alog.TestApp.Unique.changeset(%{name: "unique item"}) | ||
|> Alog.TestApp.Unique.insert() | ||
end | ||
end | ||
end | ||
# use Alog.TestApp.DataCase | ||
# doctest Alog | ||
# | ||
# describe "required fields" do | ||
# test "schema without delete field raises error" do | ||
# assert_raise RuntimeError, fn -> | ||
# defmodule NoDeleteSchema do | ||
# use Ecto.Schema | ||
# use Alog | ||
# | ||
# schema "bad_schema" do | ||
# field(:entry_id, :string) | ||
# timestamps() | ||
# end | ||
# end | ||
# end | ||
# end | ||
# | ||
# test "schema without entry_id field raises error" do | ||
# assert_raise RuntimeError, fn -> | ||
# defmodule NoEntrySchema do | ||
# use Ecto.Schema | ||
# use Alog | ||
# | ||
# schema "bad_schema" do | ||
# field(:deleted, :boolean, default: false) | ||
# timestamps() | ||
# end | ||
# end | ||
# end | ||
# end | ||
# | ||
# test "schema with deleted field of wrong type raises error" do | ||
# assert_raise RuntimeError, fn -> | ||
# defmodule BadDeletedSchema do | ||
# use Ecto.Schema | ||
# use Alog | ||
# | ||
# schema "bad_schema" do | ||
# field(:entry_id, :string) | ||
# field(:deleted, :string) | ||
# timestamps() | ||
# end | ||
# end | ||
# end | ||
# end | ||
# | ||
# test "both required fields do not raise error" do | ||
# assert (fn -> | ||
# defmodule GoodSchema do | ||
# use Ecto.Schema | ||
# use Alog | ||
# | ||
# schema "bad_schema" do | ||
# field(:entry_id, :string) | ||
# field(:deleted, :boolean, default: false) | ||
# timestamps() | ||
# end | ||
# end | ||
# end).() | ||
# end | ||
# end | ||
# | ||
# describe "Not compatible with unique index" do | ||
# test "Throws error if unique index exists" do | ||
# assert_raise RuntimeError, fn -> | ||
# %Alog.TestApp.Unique{} | ||
# |> Alog.TestApp.Unique.changeset(%{name: "unique item"}) | ||
# |> Alog.TestApp.Unique.insert() | ||
# end | ||
# end | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
defmodule AlogTest.ConstraintTest do | ||
use Alog.TestApp.DataCase | ||
|
||
alias Alog.TestApp.{User, Helpers} | ||
|
||
describe "apply_constraints/1:" do | ||
test "returns error if not unique on insert" do | ||
{:ok, user_1} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
|
||
assert {:error, user_2} = | ||
%User{} | ||
|> User.changeset( | ||
Helpers.user_2_params() | ||
|> Map.merge(%{username: user_1.username}) | ||
) | ||
|> User.insert() | ||
|
||
assert user_2.errors == [username: {"has already been taken", []}] | ||
end | ||
|
||
test "returns error if not unique on update" do | ||
{:ok, user_1} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
{:ok, user_2} = %User{} |> User.changeset(Helpers.user_2_params()) |> User.insert() | ||
|
||
assert {:error, user_2} = | ||
user_2 | ||
|> User.changeset(%{username: user_1.username}) | ||
|> User.update() | ||
|
||
assert user_2.errors == [username: {"has already been taken", []}] | ||
end | ||
end | ||
# use Alog.TestApp.DataCase | ||
# | ||
# alias Alog.TestApp.{User, Helpers} | ||
# | ||
# describe "apply_constraints/1:" do | ||
# test "returns error if not unique on insert" do | ||
# {:ok, user_1} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# | ||
# assert {:error, user_2} = | ||
# %User{} | ||
# |> User.changeset( | ||
# Helpers.user_2_params() | ||
# |> Map.merge(%{username: user_1.username}) | ||
# ) | ||
# |> User.insert() | ||
# | ||
# assert user_2.errors == [username: {"has already been taken", []}] | ||
# end | ||
# | ||
# test "returns error if not unique on update" do | ||
# {:ok, user_1} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# {:ok, user_2} = %User{} |> User.changeset(Helpers.user_2_params()) |> User.insert() | ||
# | ||
# assert {:error, user_2} = | ||
# user_2 | ||
# |> User.changeset(%{username: user_1.username}) | ||
# |> User.update() | ||
# | ||
# assert user_2.errors == [username: {"has already been taken", []}] | ||
# end | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
defmodule AlogTest.DeleteTest do | ||
use Alog.TestApp.DataCase | ||
|
||
alias Alog.TestApp.{User, Helpers} | ||
|
||
describe "delete/1:" do | ||
test "succeeds" do | ||
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
assert {:ok, _} = User.delete(user) | ||
end | ||
|
||
test "deleted items are not retrieved with 'get'" do | ||
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
{:ok, _} = User.delete(user) | ||
|
||
assert User.get(user.entry_id) == nil | ||
end | ||
|
||
test "deleted items are not retrieved with 'all'" do | ||
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
{:ok, _} = User.delete(user) | ||
|
||
assert length(User.all()) == 0 | ||
end | ||
end | ||
|
||
describe "delete/1 - with changeset:" do | ||
test "succeeds" do | ||
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
assert {:ok, _} = user |> User.changeset(%{}) |> User.delete() | ||
end | ||
|
||
test "deleted items are not retrieved with 'get'" do | ||
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
{:ok, _} = user |> User.changeset(%{}) |> User.delete() | ||
|
||
assert User.get(user.entry_id) == nil | ||
end | ||
|
||
test "deleted items are not retrieved with 'all'" do | ||
{:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
{:ok, _} = user |> User.changeset(%{}) |> User.delete() | ||
|
||
assert length(User.all()) == 0 | ||
end | ||
end | ||
# use Alog.TestApp.DataCase | ||
# | ||
# alias Alog.TestApp.{User, Helpers} | ||
# | ||
# describe "delete/1:" do | ||
# test "succeeds" do | ||
# {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# assert {:ok, _} = User.delete(user) | ||
# end | ||
# | ||
# test "deleted items are not retrieved with 'get'" do | ||
# {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# {:ok, _} = User.delete(user) | ||
# | ||
# assert User.get(user.entry_id) == nil | ||
# end | ||
# | ||
# test "deleted items are not retrieved with 'all'" do | ||
# {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# {:ok, _} = User.delete(user) | ||
# | ||
# assert length(User.all()) == 0 | ||
# end | ||
# end | ||
# | ||
# describe "delete/1 - with changeset:" do | ||
# test "succeeds" do | ||
# {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# assert {:ok, _} = user |> User.changeset(%{}) |> User.delete() | ||
# end | ||
# | ||
# test "deleted items are not retrieved with 'get'" do | ||
# {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# {:ok, _} = user |> User.changeset(%{}) |> User.delete() | ||
# | ||
# assert User.get(user.entry_id) == nil | ||
# end | ||
# | ||
# test "deleted items are not retrieved with 'all'" do | ||
# {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() | ||
# {:ok, _} = user |> User.changeset(%{}) |> User.delete() | ||
# | ||
# assert length(User.all()) == 0 | ||
# end | ||
# end | ||
end |
Oops, something went wrong.