From 79b2de5de69796205700a90637cd130f79ecac28 Mon Sep 17 00:00:00 2001 From: Michael Guarino Date: Mon, 13 Nov 2017 15:03:12 -0500 Subject: [PATCH] Add test --- test/cereal/builders/entity_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/cereal/builders/entity_test.exs b/test/cereal/builders/entity_test.exs index fe8cb50..2014fc1 100644 --- a/test/cereal/builders/entity_test.exs +++ b/test/cereal/builders/entity_test.exs @@ -112,6 +112,15 @@ defmodule Cereal.Builders.EntityTest do assert Entity.build(context) == expected end + test "it will conditionally drop excluded fields", %{context: context} do + data = %TestModel.User{id: 1, name: "Dummy"} + opts = %{excludes: [user: "name"]} + context = %{context | data: data, serializer: UserSerializer, opts: opts} + expected = %Entity{id: 1, type: "user", attributes: %{not_an_attr: true}} + + assert Entity.build(context) == expected + end + test "it will build a deeply nested entity", %{context: context} do user = %TestModel.User{id: 1, name: "Johnny User"} comments = [%TestModel.Comment{id: 1, user: user, text: "A comment"}]