Skip to content

Expose task skills on task model and view #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/views/task_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule CodeCorps.TaskViewTest do
test "renders all attributes and relationships properly" do
task = insert(:task, order: 1000)
comment = insert(:comment, task: task)
task_skill = insert(:task_skill, task: task)

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

Expand Down Expand Up @@ -37,6 +38,14 @@ defmodule CodeCorps.TaskViewTest do
"type" => "project"
}
},
"task-skills" => %{
"data" => [
%{
"id" => task_skill.id |> Integer.to_string,
"type" => "task-skill"
}
]
},
"user" => %{
"data" => %{
"id" => task.user_id |> Integer.to_string,
Expand Down
1 change: 1 addition & 0 deletions web/models/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule CodeCorps.Task do
belongs_to :user, CodeCorps.User

has_many :comments, CodeCorps.Comment
has_many :task_skills, CodeCorps.TaskSkill

timestamps()
end
Expand Down
4 changes: 3 additions & 1 deletion web/views/task_view.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule CodeCorps.TaskView do
use CodeCorps.PreloadHelpers, default_preloads: [:project, :user, :task_list, :comments]
use CodeCorps.PreloadHelpers,
default_preloads: [:project, :user, :task_list, :task_skills, :comments]
use CodeCorps.Web, :view
use JaSerializer.PhoenixView

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

has_many :comments, serializer: CodeCorps.CommentView, identifiers: :always
has_many :task_skills, serializer: CodeCorps.TaskSkillView, identifiers: :always
end