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.CommentViewTest 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+ task = insert ( :task )
11+ user = insert ( :user )
12+ comment = insert ( :comment , user: user , task: task )
13+
14+ comment = CodeCorps.Comment
15+ |> Repo . get ( comment . id )
16+ |> Repo . preload ( [ :task , :user ] )
17+
18+ rendered_json = render ( CodeCorps.CommentView , "show.json-api" , data: comment )
19+
20+ expected_json = % {
21+ data: % {
22+ id: comment . id |> Integer . to_string ,
23+ type: "comment" ,
24+ attributes: % {
25+ "body" => comment . body ,
26+ "inserted-at" => comment . inserted_at ,
27+ "markdown" => comment . markdown ,
28+ "updated-at" => comment . updated_at
29+ } ,
30+ relationships: % {
31+ "task" => % {
32+ data: % {
33+ id: comment . task_id |> Integer . to_string ,
34+ type: "task"
35+ }
36+ } ,
37+ "user" => % {
38+ data: % {
39+ id: comment . user_id |> Integer . to_string ,
40+ type: "user"
41+ }
42+ }
43+ }
44+ } ,
45+ jsonapi: % {
46+ version: "1.0"
47+ }
48+ }
49+
50+ assert expected_json == rendered_json
51+ end
52+ end
You can’t perform that action at this time.
0 commit comments