Skip to content

Commit

Permalink
include tasks in view
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Dec 15, 2017
1 parent 44e53c1 commit 646b4c3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/code_corps_web/views/task_list_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defmodule CodeCorpsWeb.TaskListView do

has_one :project, type: "project", field: :project_id

has_many :tasks, serializer: CodeCorpsWeb.TaskView, identifiers: :always
has_many :tasks, serializer: CodeCorpsWeb.TaskIncludedView, identifiers: :always, include: true
end
13 changes: 13 additions & 0 deletions lib/code_corps_web/views/task_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ defmodule CodeCorpsWeb.TaskView do
status
end
end

defmodule CodeCorpsWeb.TaskIncludedView do
@moduledoc false
use CodeCorpsWeb, :view
use JaSerializer.PhoenixView

def type, do: "task"

attributes [
:archived, :body, :created_at, :created_from, :inserted_at, :markdown,
:modified_at, :modified_from, :number, :order, :status, :title, :updated_at
]
end
21 changes: 20 additions & 1 deletion test/lib/code_corps_web/views/task_list_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,26 @@ defmodule CodeCorpsWeb.TaskListViewTest do
},
"jsonapi" => %{
"version" => "1.0"
}
},
"included" => [%{
"attributes" => %{
"archived" => task.archived,
"body" => task.body,
"created-at" => task.created_at,
"created-from" => task.created_from,
"inserted-at" => task.inserted_at,
"markdown" => task.markdown,
"modified-at" => task.modified_at,
"modified-from" => task.modified_from,
"number" => task.number,
"order" => task.order,
"status" => task.status,
"title" => task.title,
"updated-at" => task.updated_at
},
"id" => task.id |> Integer.to_string,
"type" => "task"
}]
}

assert rendered_json == expected_json
Expand Down

0 comments on commit 646b4c3

Please sign in to comment.