Skip to content

Commit cfc84f9

Browse files
committed
Added test for project category view
Typo
1 parent e1b8dd5 commit cfc84f9

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
defmodule CodeCorps.ProjectCategoryViewTest do
2+
use CodeCorps.ConnCase, async: true
3+
4+
alias CodeCorps.Repo
5+
6+
# Bring render/3 and render_to_string/3 for testing custom views
7+
import Phoenix.View
8+
9+
test "renders all attributes and relationships properly" do
10+
project_category = insert(:project_category)
11+
12+
project_category = CodeCorps.ProjectCategory
13+
|> Repo.get(project_category.id)
14+
|> Repo.preload([:project, :category])
15+
16+
rendered_json = render(CodeCorps.ProjectCategoryView, "show.json-api", data: project_category)
17+
18+
expected_json = %{
19+
data: %{
20+
id: project_category.id |> Integer.to_string,
21+
type: "project-category",
22+
attributes: %{},
23+
relationships: %{
24+
"category" => %{
25+
data: %{id: project_category.category_id |> Integer.to_string, type: "category"}
26+
},
27+
"project" => %{
28+
data: %{id: project_category.project_id |> Integer.to_string, type: "project"}
29+
}
30+
}
31+
},
32+
jsonapi: %{
33+
version: "1.0"
34+
}
35+
}
36+
37+
assert rendered_json == expected_json
38+
end
39+
end

0 commit comments

Comments
 (0)