Skip to content

Commit cac9013

Browse files
authored
Merge pull request #696 from code-corps/expose-task-skills-on-task
Expose task skills on task model and view
2 parents 2064534 + ce8022b commit cac9013

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

test/views/task_view_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule CodeCorps.TaskViewTest do
44
test "renders all attributes and relationships properly" do
55
task = insert(:task, order: 1000)
66
comment = insert(:comment, task: task)
7+
task_skill = insert(:task_skill, task: task)
78

89
rendered_json = render(CodeCorps.TaskView, "show.json-api", data: task)
910

@@ -37,6 +38,14 @@ defmodule CodeCorps.TaskViewTest do
3738
"type" => "project"
3839
}
3940
},
41+
"task-skills" => %{
42+
"data" => [
43+
%{
44+
"id" => task_skill.id |> Integer.to_string,
45+
"type" => "task-skill"
46+
}
47+
]
48+
},
4049
"user" => %{
4150
"data" => %{
4251
"id" => task.user_id |> Integer.to_string,

web/models/task.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defmodule CodeCorps.Task do
2424
belongs_to :user, CodeCorps.User
2525

2626
has_many :comments, CodeCorps.Comment
27+
has_many :task_skills, CodeCorps.TaskSkill
2728

2829
timestamps()
2930
end

web/views/task_view.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule CodeCorps.TaskView do
2-
use CodeCorps.PreloadHelpers, default_preloads: [:project, :user, :task_list, :comments]
2+
use CodeCorps.PreloadHelpers,
3+
default_preloads: [:project, :user, :task_list, :task_skills, :comments]
34
use CodeCorps.Web, :view
45
use JaSerializer.PhoenixView
56

@@ -10,4 +11,5 @@ defmodule CodeCorps.TaskView do
1011
has_one :task_list, serializer: CodeCorps.TaskListView
1112

1213
has_many :comments, serializer: CodeCorps.CommentView, identifiers: :always
14+
has_many :task_skills, serializer: CodeCorps.TaskSkillView, identifiers: :always
1315
end

0 commit comments

Comments
 (0)