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.
test for tracking assocs - just works!
custom data from the pid ets will now be pulled directly in the callbacks so ecto will pass us the :ex_audit_custom opt in deeper recursion levels
- Loading branch information
Showing
6 changed files
with
57 additions
and
7 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
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,9 @@ | ||
defmodule ExAudit.Test.Util do | ||
alias ExAudit.Test.{Repo, User} | ||
|
||
def create_user(name \\ "Admin", email \\ "admin@example.com") do | ||
params = %{name: name, email: email} | ||
changeset = User.changeset(%User{}, params) | ||
Repo.insert!(changeset) | ||
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
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,28 @@ | ||
defmodule AssocTest do | ||
use ExUnit.Case | ||
|
||
import Ecto.Query | ||
|
||
alias ExAudit.Test.{Repo, User, Version, BlogPost, Comment, Util} | ||
|
||
test "comment lifecycle tracked" do | ||
user = Util.create_user() | ||
|
||
params = %{ | ||
title: "Controversial post", | ||
author_id: user.id, | ||
comments: [ | ||
%{ | ||
body: "lorem impusdrfnia", | ||
author_id: user.id | ||
} | ||
] | ||
} | ||
|
||
changeset = BlogPost.changeset(%BlogPost{}, params) | ||
{:ok, %{comments: [comment]} = blog_post} = Repo.insert(changeset) | ||
|
||
comment_history = Repo.history(comment) | ||
assert length(comment_history) == 1 | ||
end | ||
end |