Skip to content

Commit 491e218

Browse files
vishaldeepakjoshsmith
authored andcommitted
Added archived field to Task model
1 parent d46c260 commit 491e218

6 files changed

Lines changed: 26 additions & 6 deletions

File tree

lib/code_corps/model/task.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule CodeCorps.Task do
99
@type t :: %__MODULE__{}
1010

1111
schema "tasks" do
12+
field :archived, :boolean, default: false
1213
field :body, :string
1314
field :closed_at, :utc_datetime
1415
field :created_at, :utc_datetime
@@ -63,7 +64,7 @@ defmodule CodeCorps.Task do
6364
def update_changeset(struct, params) do
6465
struct
6566
|> changeset(params)
66-
|> cast(params, [:status])
67+
|> cast(params, [:archived, :status])
6768
|> validate_inclusion(:status, statuses())
6869
|> set_closed_at()
6970
|> update_modified_at()

lib/code_corps_web/views/task_view.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ defmodule CodeCorpsWeb.TaskView do
55
use JaSerializer.PhoenixView
66

77
attributes [
8-
:body, :created_at, :created_from, :inserted_at, :markdown, :modified_at,
9-
:modified_from, :number, :order, :status, :title, :updated_at
8+
:archived, :body, :created_at, :created_from, :inserted_at, :markdown,
9+
:modified_at, :modified_from, :number, :order, :status, :title, :updated_at
1010
]
1111

1212
has_one :github_repo, serializer: CodeCorpsWeb.GithubRepoView
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule CodeCorps.Repo.Migrations.AddArchivedToTasks do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:tasks) do
6+
add :archived, :boolean, null: false, default: false
7+
end
8+
end
9+
end

priv/repo/structure.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,8 @@ CREATE TABLE tasks (
13761376
created_at timestamp without time zone,
13771377
modified_at timestamp without time zone,
13781378
created_from character varying(255) DEFAULT 'code_corps'::character varying,
1379-
modified_from character varying(255) DEFAULT 'code_corps'::character varying
1379+
modified_from character varying(255) DEFAULT 'code_corps'::character varying,
1380+
archived boolean DEFAULT false NOT NULL
13801381
);
13811382

13821383

@@ -3051,5 +3052,5 @@ ALTER TABLE ONLY user_tasks
30513052
-- PostgreSQL database dump complete
30523053
--
30533054

3054-
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003134956), (20171003225853), (20171006161407);
3055+
INSERT INTO "schema_migrations" (version) VALUES (20160723215749), (20160804000000), (20160804001111), (20160805132301), (20160805203929), (20160808143454), (20160809214736), (20160810124357), (20160815125009), (20160815143002), (20160816020347), (20160816034021), (20160817220118), (20160818000944), (20160818132546), (20160820113856), (20160820164905), (20160822002438), (20160822004056), (20160822011624), (20160822020401), (20160822044612), (20160830081224), (20160830224802), (20160911233738), (20160912002705), (20160912145957), (20160918003206), (20160928232404), (20161003185918), (20161019090945), (20161019110737), (20161020144622), (20161021131026), (20161031001615), (20161121005339), (20161121014050), (20161121043941), (20161121045709), (20161122015942), (20161123081114), (20161123150943), (20161124085742), (20161125200620), (20161126045705), (20161127054559), (20161205024856), (20161207112519), (20161209192504), (20161212005641), (20161214005935), (20161215052051), (20161216051447), (20161218005913), (20161219160401), (20161219163909), (20161220141753), (20161221085759), (20161226213600), (20161231063614), (20170102130055), (20170102181053), (20170104113708), (20170104212623), (20170104235423), (20170106013143), (20170115035159), (20170115230549), (20170121014100), (20170131234029), (20170201014901), (20170201025454), (20170201035458), (20170201183258), (20170220032224), (20170224233516), (20170226050552), (20170228085250), (20170308214128), (20170308220713), (20170308222552), (20170313130611), (20170318032449), (20170318082740), (20170324194827), (20170424215355), (20170501225441), (20170505224222), (20170526095401), (20170602000208), (20170622205732), (20170626231059), (20170628092119), (20170628213609), (20170629183404), (20170630140136), (20170706132431), (20170707213648), (20170711122252), (20170717092127), (20170725060612), (20170727052644), (20170731130121), (20170814131722), (20170913114958), (20170921014405), (20170925214512), (20170925230419), (20170926134646), (20170927100300), (20170928234412), (20171003134956), (20171003225853), (20171006063358), (20171006161407);
30553056

test/lib/code_corps/model/task_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,13 @@ defmodule CodeCorps.TaskTest do
7070
assert changeset.valid?
7171
refute closed_at
7272
end
73+
74+
test "archived field changes appropriately" do
75+
changes = Map.put(@valid_attrs, :archived, true)
76+
changeset = Task.update_changeset(%Task{task_list_id: 1}, changes)
77+
%{archived: archived} = changeset.changes
78+
assert changeset.valid?
79+
assert archived
80+
end
7381
end
7482
end

test/lib/code_corps_web/views/task_view_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defmodule CodeCorpsWeb.TaskViewTest do
1313
expected_json = %{
1414
"data" => %{
1515
"attributes" => %{
16+
"archived" => task.archived,
1617
"body" => task.body,
1718
"created-at" => task.created_at,
1819
"created-from" => task.created_from,
@@ -24,7 +25,7 @@ defmodule CodeCorpsWeb.TaskViewTest do
2425
"order" => task.order,
2526
"status" => task.status,
2627
"title" => task.title,
27-
"updated-at" => task.updated_at,
28+
"updated-at" => task.updated_at
2829
},
2930
"id" => task.id |> Integer.to_string,
3031
"relationships" => %{

0 commit comments

Comments
 (0)