Skip to content

Commit 2421e22

Browse files
authored
Merge pull request #635 from code-corps/dleve123-djl-order-task-lists
Set proper order for default task lists of a project
2 parents 08dcf7d + bdb2b5b commit 2421e22

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

test/models/project_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ defmodule CodeCorps.ProjectTest do
6262
changeset = Project.create_changeset(%Project{}, %{organization_id: 1})
6363
assert {:ok, 1} == changeset |> fetch_change(:organization_id)
6464
end
65+
66+
test "associates the ordered default task lists to the project" do
67+
organization = insert(:organization)
68+
changeset = Project.create_changeset(
69+
%Project{},
70+
%{organization_id: organization.id, title: "Title"}
71+
)
72+
73+
{_, project} = Repo.insert(changeset)
74+
75+
task_list_orders = for task_list <- project.task_lists, do: task_list.order
76+
77+
assert Enum.all?(task_list_orders), "some of the orders are not set (nil)"
78+
assert task_list_orders == Enum.sort(task_list_orders), "task lists order does not correspond to their position"
79+
end
6580
end
6681

6782
describe "update_changeset/2" do

web/models/task_list.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule CodeCorps.TaskList do
22
use CodeCorps.Web, :model
33
import EctoOrdered
44

5+
alias CodeCorps.TaskList
6+
57
schema "task_lists" do
68
field :inbox, :boolean, default: false
79
field :name, :string
@@ -33,7 +35,7 @@ defmodule CodeCorps.TaskList do
3335
name: "Done",
3436
position: 4
3537
}
36-
]
38+
] |> Enum.map(fn (params) -> changeset(%TaskList{}, params) end)
3739
end
3840

3941
@doc """

0 commit comments

Comments
 (0)