File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments