diff --git a/lib/code_corps/model/task.ex b/lib/code_corps/model/task.ex index 7788f9f47..4c668e643 100644 --- a/lib/code_corps/model/task.ex +++ b/lib/code_corps/model/task.ex @@ -4,10 +4,12 @@ defmodule CodeCorps.Task do import EctoOrdered alias CodeCorps.Services.MarkdownRendererService + alias Ecto.Changeset @type t :: %__MODULE__{} schema "tasks" do + field :closed_at, :utc_datetime field :body, :string field :markdown, :string field :number, :integer, read_after_writes: true @@ -58,6 +60,7 @@ defmodule CodeCorps.Task do |> changeset(params) |> cast(params, [:status]) |> validate_inclusion(:status, statuses()) + |> set_closed_at() end def apply_position(changeset) do @@ -71,4 +74,15 @@ defmodule CodeCorps.Task do defp statuses do ~w{ open closed } end + + defp set_closed_at(changeset) do + case changeset do + %Changeset{valid?: true, changes: %{status: "closed"}} -> + put_change(changeset, :closed_at, DateTime.utc_now) + %Changeset{valid?: true, changes: %{status: "open"}} -> + put_change(changeset, :closed_at, nil) + _ -> + changeset + end + end end diff --git a/priv/repo/migrations/20170927100300_add_closed_at_to_tasks.exs b/priv/repo/migrations/20170927100300_add_closed_at_to_tasks.exs new file mode 100644 index 000000000..f542f22b9 --- /dev/null +++ b/priv/repo/migrations/20170927100300_add_closed_at_to_tasks.exs @@ -0,0 +1,9 @@ +defmodule CodeCorps.Repo.Migrations.AddClosedAtToTasks do + use Ecto.Migration + + def change do + alter table(:tasks) do + add :closed_at, :utc_datetime + end + end +end \ No newline at end of file diff --git a/priv/repo/structure.sql b/priv/repo/structure.sql index c38f06130..54ab7edd9 100644 --- a/priv/repo/structure.sql +++ b/priv/repo/structure.sql @@ -55,9 +55,9 @@ SET default_with_oids = false; -- CREATE TABLE auth_token ( - id integer NOT NULL, + id bigint NOT NULL, value character varying(255), - user_id integer, + user_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -87,7 +87,7 @@ ALTER SEQUENCE auth_token_id_seq OWNED BY auth_token.id; -- CREATE TABLE categories ( - id integer NOT NULL, + id bigint NOT NULL, name character varying(255) NOT NULL, slug character varying(255) NOT NULL, description text, @@ -120,11 +120,11 @@ ALTER SEQUENCE categories_id_seq OWNED BY categories.id; -- CREATE TABLE comments ( - id integer NOT NULL, + id bigint NOT NULL, body text NOT NULL, markdown text, - user_id integer NOT NULL, - task_id integer NOT NULL, + user_id bigint NOT NULL, + task_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, github_id integer @@ -155,10 +155,10 @@ ALTER SEQUENCE comments_id_seq OWNED BY comments.id; -- CREATE TABLE donation_goals ( - id integer NOT NULL, + id bigint NOT NULL, amount integer, description text, - project_id integer, + project_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, current boolean DEFAULT false @@ -189,12 +189,12 @@ ALTER SEQUENCE donation_goals_id_seq OWNED BY donation_goals.id; -- CREATE TABLE github_app_installations ( - id integer NOT NULL, + id bigint NOT NULL, github_id integer, installed boolean DEFAULT true, state character varying(255), - project_id integer, - user_id integer, + project_id bigint, + user_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, access_token character varying(255), @@ -232,7 +232,7 @@ ALTER SEQUENCE github_app_installations_id_seq OWNED BY github_app_installations -- CREATE TABLE github_events ( - id integer NOT NULL, + id bigint NOT NULL, action character varying(255), github_delivery_id character varying(255), status character varying(255), @@ -268,14 +268,14 @@ ALTER SEQUENCE github_events_id_seq OWNED BY github_events.id; -- CREATE TABLE github_repos ( - id integer NOT NULL, + id bigint NOT NULL, github_id integer, name character varying(255), github_account_id integer, github_account_login character varying(255), github_account_avatar_url character varying(255), github_account_type character varying(255), - github_app_installation_id integer, + github_app_installation_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -305,9 +305,9 @@ ALTER SEQUENCE github_repos_id_seq OWNED BY github_repos.id; -- CREATE TABLE organization_github_app_installations ( - id integer NOT NULL, - organization_id integer, - github_app_installation_id integer, + id bigint NOT NULL, + organization_id bigint, + github_app_installation_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -337,7 +337,7 @@ ALTER SEQUENCE organization_github_app_installations_id_seq OWNED BY organizatio -- CREATE TABLE organization_invites ( - id integer NOT NULL, + id bigint NOT NULL, code character varying(255) NOT NULL, email character varying(255) NOT NULL, title character varying(255) NOT NULL, @@ -371,7 +371,7 @@ ALTER SEQUENCE organization_invites_id_seq OWNED BY organization_invites.id; -- CREATE TABLE organizations ( - id integer NOT NULL, + id bigint NOT NULL, name text NOT NULL, description text NOT NULL, slug character varying(255) NOT NULL, @@ -380,7 +380,7 @@ CREATE TABLE organizations ( approved boolean DEFAULT false, cloudinary_public_id character varying(255), default_color character varying(255), - owner_id integer + owner_id bigint ); @@ -408,10 +408,10 @@ ALTER SEQUENCE organizations_id_seq OWNED BY organizations.id; -- CREATE TABLE previews ( - id integer NOT NULL, + id bigint NOT NULL, markdown text NOT NULL, body text NOT NULL, - user_id integer NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -441,9 +441,9 @@ ALTER SEQUENCE previews_id_seq OWNED BY previews.id; -- CREATE TABLE project_categories ( - id integer NOT NULL, - project_id integer NOT NULL, - category_id integer NOT NULL, + id bigint NOT NULL, + project_id bigint NOT NULL, + category_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -473,9 +473,9 @@ ALTER SEQUENCE project_categories_id_seq OWNED BY project_categories.id; -- CREATE TABLE project_github_repos ( - id integer NOT NULL, - project_id integer, - github_repo_id integer, + id bigint NOT NULL, + project_id bigint, + github_repo_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -505,9 +505,9 @@ ALTER SEQUENCE project_github_repos_id_seq OWNED BY project_github_repos.id; -- CREATE TABLE project_skills ( - id integer NOT NULL, - project_id integer NOT NULL, - skill_id integer NOT NULL, + id bigint NOT NULL, + project_id bigint NOT NULL, + skill_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -537,10 +537,10 @@ ALTER SEQUENCE project_skills_id_seq OWNED BY project_skills.id; -- CREATE TABLE project_users ( - id integer NOT NULL, + id bigint NOT NULL, role character varying(255) NOT NULL, - project_id integer NOT NULL, - user_id integer NOT NULL, + project_id bigint NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -570,13 +570,13 @@ ALTER SEQUENCE project_users_id_seq OWNED BY project_users.id; -- CREATE TABLE projects ( - id integer NOT NULL, + id bigint NOT NULL, description text, long_description_body text, long_description_markdown text, slug character varying(255) NOT NULL, title character varying(255) NOT NULL, - organization_id integer NOT NULL, + organization_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, total_monthly_donated integer DEFAULT 0, @@ -615,9 +615,9 @@ ALTER SEQUENCE projects_id_seq OWNED BY projects.id; -- CREATE TABLE role_skills ( - id integer NOT NULL, - role_id integer NOT NULL, - skill_id integer NOT NULL, + id bigint NOT NULL, + role_id bigint NOT NULL, + skill_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, cat integer @@ -648,7 +648,7 @@ ALTER SEQUENCE role_skills_id_seq OWNED BY role_skills.id; -- CREATE TABLE roles ( - id integer NOT NULL, + id bigint NOT NULL, name character varying(255) NOT NULL, ability character varying(255) NOT NULL, kind character varying(255) NOT NULL, @@ -691,7 +691,7 @@ CREATE TABLE schema_migrations ( -- CREATE TABLE skills ( - id integer NOT NULL, + id bigint NOT NULL, title character varying(255) NOT NULL, description text, original_row integer, @@ -724,10 +724,10 @@ ALTER SEQUENCE skills_id_seq OWNED BY skills.id; -- CREATE TABLE slugged_routes ( - id integer NOT NULL, + id bigint NOT NULL, slug character varying(255) NOT NULL, - organization_id integer, - user_id integer, + organization_id bigint, + user_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -757,7 +757,7 @@ ALTER SEQUENCE slugged_routes_id_seq OWNED BY slugged_routes.id; -- CREATE TABLE stripe_connect_accounts ( - id integer NOT NULL, + id bigint NOT NULL, business_name character varying(255), business_url character varying(255), charges_enabled boolean, @@ -772,7 +772,7 @@ CREATE TABLE stripe_connect_accounts ( support_phone character varying(255), support_url character varying(255), transfers_enabled boolean, - organization_id integer NOT NULL, + organization_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, verification_disabled_reason character varying(255), @@ -839,10 +839,10 @@ ALTER SEQUENCE stripe_connect_accounts_id_seq OWNED BY stripe_connect_accounts.i -- CREATE TABLE stripe_connect_cards ( - id integer NOT NULL, + id bigint NOT NULL, id_from_stripe character varying(255) NOT NULL, - stripe_connect_account_id integer NOT NULL, - stripe_platform_card_id integer NOT NULL, + stripe_connect_account_id bigint NOT NULL, + stripe_platform_card_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -872,7 +872,7 @@ ALTER SEQUENCE stripe_connect_cards_id_seq OWNED BY stripe_connect_cards.id; -- CREATE TABLE stripe_connect_charges ( - id integer NOT NULL, + id bigint NOT NULL, amount integer, amount_refunded integer, application_id_from_stripe character varying(255), @@ -893,9 +893,9 @@ CREATE TABLE stripe_connect_charges ( source_transfer_id_from_stripe character varying(255), statement_descriptor character varying(255), status character varying(255), - stripe_connect_account_id integer, - stripe_connect_customer_id integer NOT NULL, - user_id integer NOT NULL, + stripe_connect_account_id bigint, + stripe_connect_customer_id bigint NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -925,13 +925,13 @@ ALTER SEQUENCE stripe_connect_charges_id_seq OWNED BY stripe_connect_charges.id; -- CREATE TABLE stripe_connect_customers ( - id integer NOT NULL, + id bigint NOT NULL, id_from_stripe character varying(255) NOT NULL, - stripe_connect_account_id integer NOT NULL, - stripe_platform_customer_id integer NOT NULL, + stripe_connect_account_id bigint NOT NULL, + stripe_platform_customer_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - user_id integer NOT NULL + user_id bigint NOT NULL ); @@ -959,11 +959,11 @@ ALTER SEQUENCE stripe_connect_customers_id_seq OWNED BY stripe_connect_customers -- CREATE TABLE stripe_connect_plans ( - id integer NOT NULL, + id bigint NOT NULL, amount integer, id_from_stripe character varying(255) NOT NULL, name character varying(255), - project_id integer NOT NULL, + project_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, created integer @@ -994,15 +994,15 @@ ALTER SEQUENCE stripe_connect_plans_id_seq OWNED BY stripe_connect_plans.id; -- CREATE TABLE stripe_connect_subscriptions ( - id integer NOT NULL, + id bigint NOT NULL, application_fee_percent numeric, customer_id_from_stripe character varying(255), id_from_stripe character varying(255) NOT NULL, plan_id_from_stripe character varying(255) NOT NULL, quantity integer, status character varying(255), - stripe_connect_plan_id integer NOT NULL, - user_id integer, + stripe_connect_plan_id bigint NOT NULL, + user_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, cancelled_at integer, @@ -1038,7 +1038,7 @@ ALTER SEQUENCE stripe_connect_subscriptions_id_seq OWNED BY stripe_connect_subsc -- CREATE TABLE stripe_events ( - id integer NOT NULL, + id bigint NOT NULL, id_from_stripe character varying(255) NOT NULL, status character varying(255) DEFAULT 'unprocessed'::character varying, type character varying(255) NOT NULL, @@ -1076,7 +1076,7 @@ ALTER SEQUENCE stripe_events_id_seq OWNED BY stripe_events.id; -- CREATE TABLE stripe_external_accounts ( - id integer NOT NULL, + id bigint NOT NULL, id_from_stripe character varying(255) NOT NULL, account_id_from_stripe character varying(255) NOT NULL, account_holder_name character varying(255), @@ -1091,7 +1091,7 @@ CREATE TABLE stripe_external_accounts ( inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, default_for_currency boolean, - stripe_connect_account_id integer + stripe_connect_account_id bigint ); @@ -1119,13 +1119,13 @@ ALTER SEQUENCE stripe_external_accounts_id_seq OWNED BY stripe_external_accounts -- CREATE TABLE stripe_file_upload ( - id integer NOT NULL, + id bigint NOT NULL, id_from_stripe character varying(255) NOT NULL, purpose character varying(255), size integer, type character varying(255), url character varying(255), - stripe_connect_account_id integer, + stripe_connect_account_id bigint, created integer ); @@ -1154,7 +1154,7 @@ ALTER SEQUENCE stripe_file_upload_id_seq OWNED BY stripe_file_upload.id; -- CREATE TABLE stripe_invoices ( - id integer NOT NULL, + id bigint NOT NULL, amount_due integer, application_fee integer, attempt_count integer, @@ -1182,8 +1182,8 @@ CREATE TABLE stripe_invoices ( tax_percent double precision, total integer, webhooks_delievered_at integer, - stripe_connect_subscription_id integer NOT NULL, - user_id integer NOT NULL, + stripe_connect_subscription_id bigint NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1213,7 +1213,7 @@ ALTER SEQUENCE stripe_invoices_id_seq OWNED BY stripe_invoices.id; -- CREATE TABLE stripe_platform_cards ( - id integer NOT NULL, + id bigint NOT NULL, brand character varying(255), customer_id_from_stripe character varying(255), cvc_check character varying(255), @@ -1222,7 +1222,7 @@ CREATE TABLE stripe_platform_cards ( id_from_stripe character varying(255) NOT NULL, last4 character varying(255), name character varying(255), - user_id integer NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1252,12 +1252,12 @@ ALTER SEQUENCE stripe_platform_cards_id_seq OWNED BY stripe_platform_cards.id; -- CREATE TABLE stripe_platform_customers ( - id integer NOT NULL, + id bigint NOT NULL, currency character varying(255), delinquent boolean, email character varying(255), id_from_stripe character varying(255) NOT NULL, - user_id integer NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, created integer @@ -1288,10 +1288,10 @@ ALTER SEQUENCE stripe_platform_customers_id_seq OWNED BY stripe_platform_custome -- CREATE TABLE task_lists ( - id integer NOT NULL, + id bigint NOT NULL, name character varying(255), "order" integer, - project_id integer, + project_id bigint, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, inbox boolean DEFAULT false @@ -1322,9 +1322,9 @@ ALTER SEQUENCE task_lists_id_seq OWNED BY task_lists.id; -- CREATE TABLE task_skills ( - id integer NOT NULL, - skill_id integer NOT NULL, - task_id integer NOT NULL, + id bigint NOT NULL, + skill_id bigint NOT NULL, + task_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1354,20 +1354,21 @@ ALTER SEQUENCE task_skills_id_seq OWNED BY task_skills.id; -- CREATE TABLE tasks ( - id integer NOT NULL, + id bigint NOT NULL, body text, markdown text, number integer NOT NULL, status character varying(255) DEFAULT 'open'::character varying NOT NULL, title text NOT NULL, - project_id integer NOT NULL, - user_id integer NOT NULL, + project_id bigint NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - task_list_id integer, + task_list_id bigint, "order" integer, github_issue_number integer, - github_repo_id integer + github_repo_id bigint, + closed_at timestamp without time zone ); @@ -1395,9 +1396,9 @@ ALTER SEQUENCE tasks_id_seq OWNED BY tasks.id; -- CREATE TABLE user_categories ( - id integer NOT NULL, - user_id integer NOT NULL, - category_id integer NOT NULL, + id bigint NOT NULL, + user_id bigint NOT NULL, + category_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1427,9 +1428,9 @@ ALTER SEQUENCE user_categories_id_seq OWNED BY user_categories.id; -- CREATE TABLE user_roles ( - id integer NOT NULL, - user_id integer NOT NULL, - role_id integer NOT NULL, + id bigint NOT NULL, + user_id bigint NOT NULL, + role_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1459,9 +1460,9 @@ ALTER SEQUENCE user_roles_id_seq OWNED BY user_roles.id; -- CREATE TABLE user_skills ( - id integer NOT NULL, - user_id integer NOT NULL, - skill_id integer NOT NULL, + id bigint NOT NULL, + user_id bigint NOT NULL, + skill_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1491,9 +1492,9 @@ ALTER SEQUENCE user_skills_id_seq OWNED BY user_skills.id; -- CREATE TABLE user_tasks ( - id integer NOT NULL, - task_id integer NOT NULL, - user_id integer NOT NULL, + id bigint NOT NULL, + task_id bigint NOT NULL, + user_id bigint NOT NULL, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -1523,7 +1524,7 @@ ALTER SEQUENCE user_tasks_id_seq OWNED BY user_tasks.id; -- CREATE TABLE users ( - id integer NOT NULL, + id bigint NOT NULL, username character varying(255), email character varying(255), encrypted_password character varying(255), @@ -3035,5 +3036,5 @@ ALTER TABLE ONLY user_tasks -- PostgreSQL database dump complete -- -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); +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); diff --git a/test/lib/code_corps/model/task_test.exs b/test/lib/code_corps/model/task_test.exs index d09ad7713..f854a28e7 100644 --- a/test/lib/code_corps/model/task_test.exs +++ b/test/lib/code_corps/model/task_test.exs @@ -34,8 +34,24 @@ defmodule CodeCorps.TaskTest do describe "update_changeset/2" do test "only allows specific values for status" do changes = Map.put(@valid_attrs, :status, "nonexistent") - changeset = Task.update_changeset(%Task{}, changes) + changeset = Task.update_changeset(%Task{task_list_id: 1}, changes) refute changeset.valid? end + + test "closed_at is set when status changes to closed" do + changes = Map.put(@valid_attrs, :status, "closed") + changeset = Task.update_changeset(%Task{task_list_id: 1}, changes) + %{closed_at: closed_at} = changeset.changes + assert changeset.valid? + assert closed_at + end + + test "closed_at is set to nil when status changes to open" do + changes = Map.put(@valid_attrs, :status, "open") + changeset = Task.update_changeset(%Task{task_list_id: 1, status: "closed", closed_at: DateTime.utc_now}, changes) + %{closed_at: closed_at} = changeset.changes + assert changeset.valid? + refute closed_at + end end end