forked from ZennerIoT/ex_audit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZennerIoT#14 Validates precision is set for recorded_at
- Loading branch information
1 parent
937918a
commit 4732039
Showing
2 changed files
with
39 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule PrecisionTest do | ||
use ExUnit.Case | ||
|
||
import Ecto.Query | ||
|
||
alias ExAudit.Test.{Repo, User, Version, Util} | ||
|
||
setup_all do | ||
current = Application.get_env(:ex_audit, :precision) | ||
|
||
Application.put_env(:ex_audit, :precision, :microsecond) | ||
|
||
on_exit(fn -> Application.put_env(:ex_audit, :precision, current) end) | ||
end | ||
|
||
test "adjust the precision to `second` in the field `recorded_at`" do | ||
user = Util.create_user("Juan Zuñiga") | ||
|
||
changeset = User.changeset(user, %{name: "@neodevelop"}) | ||
|
||
assert {:ok, user} = Repo.update(changeset) | ||
|
||
query = | ||
from(v in Version, | ||
where: v.entity_id == ^user.id, | ||
where: v.entity_schema == ^User | ||
) | ||
|
||
assert 2 = Repo.aggregate(query, :count, :id) | ||
end | ||
end |