Skip to content

Commit

Permalink
seperating UUID tests from the test trial
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Mar 1, 2020
1 parent 0fa068f commit 05c9560
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
command: |
apk add docker-compose
sed -i $(echo "s/\$CIRCLE_BRANCH/$CIRCLE_BRANCH/g") /code/.env
docker-compose up -d
- run: docker-compose exec -T backend mix test --trace
- run: docker-compose run backend mix test --only describe:"PaperTrailTest.UUIDTest" --trace
- run: docker-compose run backend mix test --exclude describe:"PaperTrailTest.UUIDTest" --trace
- run: exit 0


workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ADD . /code/

RUN mix compile

ENTRYPOINT "/bin/sh"
CMD ["/bin/sh"]

# mix ecto.create
# mix ecto.migrate
99 changes: 51 additions & 48 deletions test/paper_trail/uuid_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,78 @@ defmodule PaperTrailTest.UUIDTest do

Code.eval_file("lib/paper_trail.ex")
Code.eval_file("lib/version.ex")

repo().delete_all(Version)
repo().delete_all(Admin)
repo().delete_all(Product)
repo().delete_all(Item)
:ok
end

test "creates versions with models that have a UUID primary key" do
product =
%Product{}
|> Product.changeset(%{name: "Hair Cream"})
|> PaperTrail.insert!()

version = Version |> last |> repo().one

assert version.item_id == product.id
assert version.item_type == "Product"
end
describe "PaperTrailTest.UUIDTest" do
test "creates versions with models that have a UUID primary key" do
product =
%Product{}
|> Product.changeset(%{name: "Hair Cream"})
|> PaperTrail.insert!()

test "handles originators with a UUID primary key" do
admin =
%Admin{}
|> Admin.changeset(%{email: "admin@example.com"})
|> repo().insert!
version = Version |> last |> repo().one

%Product{}
|> Product.changeset(%{name: "Hair Cream"})
|> PaperTrail.insert!(originator: admin)
assert version.item_id == product.id
assert version.item_type == "Product"
end

version =
Version
|> last
|> repo().one
|> repo().preload(:admin)
test "handles originators with a UUID primary key" do
admin =
%Admin{}
|> Admin.changeset(%{email: "admin@example.com"})
|> repo().insert!

assert version.admin == admin
end
%Product{}
|> Product.changeset(%{name: "Hair Cream"})
|> PaperTrail.insert!(originator: admin)

test "versioning models that have a non-regular primary key" do
item =
%Item{}
|> Item.changeset(%{title: "hello"})
|> PaperTrail.insert!()
version =
Version
|> last
|> repo().one
|> repo().preload(:admin)

version = Version |> last |> repo().one
assert version.item_id == item.item_id
end
assert version.admin == admin
end

test "test INTEGER primary key for item_type == :string" do
if PaperTrail.Version.__schema__(:type, :item_id) == :string do
test "versioning models that have a non-regular primary key" do
item =
%FooItem{}
|> FooItem.changeset(%{title: "hello"})
%Item{}
|> Item.changeset(%{title: "hello"})
|> PaperTrail.insert!()

version = Version |> last |> repo().one
assert version.item_id == "#{item.id}"
assert version.item_id == item.item_id
end
end

test "test STRING primary key for item_type == :string" do
if PaperTrail.Version.__schema__(:type, :item_id) == :string do
item =
%BarItem{}
|> BarItem.changeset(%{item_id: "#{:os.system_time()}", title: "hello"})
|> PaperTrail.insert!()
test "test INTEGER primary key for item_type == :string" do
if PaperTrail.Version.__schema__(:type, :item_id) == :string do
item =
%FooItem{}
|> FooItem.changeset(%{title: "hello"})
|> PaperTrail.insert!()

version = Version |> last |> repo().one
assert version.item_id == item.item_id
version = Version |> last |> repo().one
assert version.item_id == "#{item.id}"
end
end

test "test STRING primary key for item_type == :string" do
if PaperTrail.Version.__schema__(:type, :item_id) == :string do
item =
%BarItem{}
|> BarItem.changeset(%{item_id: "#{:os.system_time()}", title: "hello"})
|> PaperTrail.insert!()

version = Version |> last |> repo().one
assert version.item_id == item.item_id
end
end
end
end

0 comments on commit 05c9560

Please sign in to comment.