Skip to content

Commit 4a122fc

Browse files
committed
Add TaskSkillView and test
1 parent 90b4a71 commit 4a122fc

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
defmodule CodeCorps.TaskSkillViewTest do
2+
@moduledoc false
3+
4+
use CodeCorps.ViewCase
5+
6+
test "renders all attributes and relationships properly" do
7+
task_skill = insert(:task_skill)
8+
9+
rendered_json = render(CodeCorps.TaskSkillView, "show.json-api", data: task_skill)
10+
11+
expected_json = %{
12+
"data" => %{
13+
"id" => task_skill.id |> Integer.to_string,
14+
"type" => "task-skill",
15+
"attributes" => %{},
16+
"relationships" => %{
17+
"task" => %{
18+
"data" => %{"id" => task_skill.task_id |> Integer.to_string, "type" => "task"}
19+
},
20+
"skill" => %{
21+
"data" => %{"id" => task_skill.skill_id |> Integer.to_string, "type" => "skill"}
22+
}
23+
}
24+
},
25+
"jsonapi" => %{
26+
"version" => "1.0"
27+
}
28+
}
29+
30+
assert rendered_json == expected_json
31+
end
32+
end

web/views/task_skill_view.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule CodeCorps.TaskSkillView do
2+
use CodeCorps.PreloadHelpers, default_preloads: [:task, :skill]
3+
use CodeCorps.Web, :view
4+
use JaSerializer.PhoenixView
5+
6+
has_one :task, serializer: CodeCorps.TaskView
7+
has_one :skill, serializer: CodeCorps.SkillView
8+
end

0 commit comments

Comments
 (0)