Skip to content

Commit

Permalink
Add inbox flag to task lists
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Jan 6, 2017
1 parent 0816489 commit 8bc8eed
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
25 changes: 25 additions & 0 deletions priv/repo/migrations/20170106013143_add_editable_to_task_lists.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule CodeCorps.Repo.Migrations.AddEditableToTaskLists do
alias CodeCorps.{Repo, TaskList}

import Ecto.Query

use Ecto.Migration

def up do
alter table(:task_lists) do
add :inbox, :boolean, default: false
end

flush

TaskList
|> where([task_list], task_list.name == "Inbox")
|> Repo.update_all(set: [inbox: true])
end

def down do
alter table(:task_lists) do
remove :inbox
end
end
end
9 changes: 9 additions & 0 deletions test/models/task_list_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ defmodule CodeCorps.TaskListTest do
changeset = TaskList.changeset(%TaskList{}, @invalid_attrs)
refute changeset.valid?
end

test "is not inbox by default" do
{:ok, record} =
%TaskList{}
|> TaskList.changeset(@valid_attrs)
|> CodeCorps.Repo.insert

refute record.inbox
end
end
1 change: 1 addition & 0 deletions test/views/task_list_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule CodeCorps.TaskListViewTest do
expected_json = %{
"data" => %{
"attributes" => %{
"inbox" => task_list.inbox,
"name" => task_list.name,
"order" => 1000,
"inserted-at" => task_list.inserted_at,
Expand Down
7 changes: 6 additions & 1 deletion web/models/task_list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ defmodule CodeCorps.TaskList do
import EctoOrdered

schema "task_lists" do
field :inbox, :boolean, default: false
field :name, :string
field :position, :integer, virtual: true
field :order, :integer
field :position, :integer, virtual: true

belongs_to :project, CodeCorps.Project
has_many :tasks, CodeCorps.Task
Expand All @@ -16,15 +17,19 @@ defmodule CodeCorps.TaskList do
def default_task_lists() do
[
%{
inbox: true,
name: "Inbox",
position: 1
}, %{
inbox: false,
name: "Backlog",
position: 2
}, %{
inbox: false,
name: "In Progress",
position: 3
}, %{
inbox: false,
name: "Done",
position: 4
}
Expand Down
2 changes: 1 addition & 1 deletion web/views/task_list_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule CodeCorps.TaskListView do
use CodeCorps.Web, :view
use JaSerializer.PhoenixView

attributes [:name, :order, :inserted_at, :updated_at]
attributes [:inbox, :name, :order, :inserted_at, :updated_at]

has_one :project, serializer: CodeCorps.ProjectView

Expand Down

0 comments on commit 8bc8eed

Please sign in to comment.