-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When preparing the user for serialization the associations are now stripped given that the associations preloading might not be required.
- Loading branch information
1 parent
0059a41
commit 97d5e9d
Showing
5 changed files
with
52 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
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,38 @@ | ||
defmodule PresenterTest do | ||
alias Addict.Presenter | ||
use ExUnit.Case, async: true | ||
|
||
test "it strips associations" do | ||
user = struct( | ||
TestAddictUserAssociationsSchema, | ||
%{ | ||
name: "Joe Doe", | ||
email: "joe.doe@example.com", | ||
encrypted_password: "what a hash!" | ||
}) | ||
|
||
model = Presenter.strip_all(user, TestAddictUserAssociationsSchema) | ||
|
||
assert Map.has_key?(model, :__struct__) == false | ||
assert Map.has_key?(model, :__meta__) == false | ||
assert Map.has_key?(model, :drugs) == false | ||
end | ||
end | ||
|
||
defmodule TestAddictDrugsSchema do | ||
use Ecto.Schema | ||
schema "drugs" do | ||
field :name, :string | ||
end | ||
end | ||
|
||
defmodule TestAddictUserAssociationsSchema do | ||
use Ecto.Schema | ||
|
||
schema "users" do | ||
field :name, :string | ||
field :email, :string | ||
field :encrypted_password, :string | ||
has_many :drugs, TestAddictDrugsSchema | ||
end | ||
end |