From cc58830444d0d8a75c3450ae1b4a175984bdc234 Mon Sep 17 00:00:00 2001 From: Josh Smith Date: Mon, 31 Oct 2016 10:48:01 -0700 Subject: [PATCH] Fix donation goals --- blueprint/api.apib | 5 +---- ...031001615_remove_title_from_donation_goals.exs | 15 +++++++++++++++ .../controllers/donation_goal_controller_test.exs | 4 ++-- test/models/donation_goal_test.exs | 10 ++++------ test/support/factories.ex | 1 - test/views/donation_goal_view_test.exs | 3 +-- web/models/donation_goal.ex | 10 ++++------ web/views/donation_goal_view.ex | 2 +- 8 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 priv/repo/migrations/20161031001615_remove_title_from_donation_goals.exs diff --git a/blueprint/api.apib b/blueprint/api.apib index 0bca8e8e2..4a1659a2c 100644 --- a/blueprint/api.apib +++ b/blueprint/api.apib @@ -2221,7 +2221,6 @@ This endpoint allows you to check whether a username is valid (by running a vali + include JSON API Version ## Donation Goal Attributes (object) -+ title: `Support the core team` (string, required) + description: `Will provide all the basic overhead costs needed to run Code Corps.` (string, required) - Several lines describing the reasons for the goal + amount: `1500000` (required, number) - The amount, in cents, for the goal. + current: `true` (required, boolean) - Indicates whether this is the current donation goal. This is determined by whether 1) this is the highest goal and the total monthly raised is higher than that amount or 2) the total monthly raised is between the lower goal's amount (if it exists) and this goal's amount. @@ -2229,12 +2228,11 @@ This endpoint allows you to check whether a username is valid (by running a vali ## Donation Goal Create Request + data + attributes - + title (string) - A title for the donation + description (string) - A short plain text description for the donation + amount (number) - the amount of money in cents for the goal + relationships + project - + data(Project Resource Identifier) - Identifier of project this donation goal is being created for + + data(Project Resource Identifier) ## Donation Goal Resource (object) + include Donation Goal Resource Identifier @@ -2258,7 +2256,6 @@ This endpoint allows you to check whether a username is valid (by running a vali ## Donation Goal Update Request + data + attributes - + title (string) - A title for the donation + description (string) - A short plain text description for the donation + amount (number) - the amount of money in cents for the goal diff --git a/priv/repo/migrations/20161031001615_remove_title_from_donation_goals.exs b/priv/repo/migrations/20161031001615_remove_title_from_donation_goals.exs new file mode 100644 index 000000000..2b0fd58c3 --- /dev/null +++ b/priv/repo/migrations/20161031001615_remove_title_from_donation_goals.exs @@ -0,0 +1,15 @@ +defmodule CodeCorps.Repo.Migrations.RemoveTitleFromDonationGoals do + use Ecto.Migration + + def up do + alter table(:donation_goals) do + remove :title + end + end + + def down do + alter table(:donation_goals) do + add :title, :string, null: false + end + end +end diff --git a/test/controllers/donation_goal_controller_test.exs b/test/controllers/donation_goal_controller_test.exs index c4abcc10a..272ebfc18 100644 --- a/test/controllers/donation_goal_controller_test.exs +++ b/test/controllers/donation_goal_controller_test.exs @@ -3,8 +3,8 @@ defmodule CodeCorps.DonationGoalControllerTest do alias CodeCorps.DonationGoal - @valid_attrs %{amount: 200, current: false, description: "A description", title: "A donation"} - @invalid_attrs %{description: nil, title: nil} + @valid_attrs %{amount: 200, current: false, description: "A description"} + @invalid_attrs %{description: nil} describe "index" do test "lists all entries on index", %{conn: conn} do diff --git a/test/models/donation_goal_test.exs b/test/models/donation_goal_test.exs index 6691dabcb..fa718a57c 100644 --- a/test/models/donation_goal_test.exs +++ b/test/models/donation_goal_test.exs @@ -4,7 +4,7 @@ defmodule CodeCorps.DonationGoalTest do alias CodeCorps.DonationGoal describe "%create_changeset/2" do - test "requires title, description, amount, current and project_id" do + test "requires amount, current, description and project_id" do changeset = DonationGoal.create_changeset(%DonationGoal{}, %{}) refute changeset.valid? @@ -12,11 +12,10 @@ defmodule CodeCorps.DonationGoalTest do assert changeset.errors[:current] == {"can't be blank", []} assert changeset.errors[:description] == {"can't be blank", []} assert changeset.errors[:project_id] == {"can't be blank", []} - assert changeset.errors[:title] == {"can't be blank", []} end test "ensures project with specified id actually exists" do - attrs = %{amount: 100, current: true, description: "Bar", project_id: -1, title: "Foo"} + attrs = %{amount: 100, current: true, description: "Bar", project_id: -1} { result, changeset } = DonationGoal.create_changeset(%DonationGoal{}, attrs) |> Repo.insert @@ -28,8 +27,8 @@ defmodule CodeCorps.DonationGoalTest do end describe "&update_changeset/2" do - test "requires title, description, amount, current" do - attrs = %{amount: nil, current: nil, description: nil, title: nil} + test "requires amount, current, description" do + attrs = %{amount: nil, current: nil, description: nil} donation_goal = insert(:donation_goal) changeset = DonationGoal.update_changeset(donation_goal, attrs) @@ -37,7 +36,6 @@ defmodule CodeCorps.DonationGoalTest do assert changeset.errors[:amount] == {"can't be blank", []} assert changeset.errors[:current] == {"can't be blank", []} assert changeset.errors[:description] == {"can't be blank", []} - assert changeset.errors[:title] == {"can't be blank", []} end end end diff --git a/test/support/factories.ex b/test/support/factories.ex index 03df631c0..16ff54c6c 100644 --- a/test/support/factories.ex +++ b/test/support/factories.ex @@ -26,7 +26,6 @@ defmodule CodeCorps.Factories do amount: 100, current: false, description: sequence(:description, &"A description for a donation goal #{&1}"), - title: sequence(:title, &"Donation goal #{&1}"), project: build(:project) } end diff --git a/test/views/donation_goal_view_test.exs b/test/views/donation_goal_view_test.exs index c79316185..a7b527108 100644 --- a/test/views/donation_goal_view_test.exs +++ b/test/views/donation_goal_view_test.exs @@ -16,8 +16,7 @@ defmodule CodeCorps.DonationGoalViewTest do "attributes" => %{ "amount" => donation_goal.amount, "current" => donation_goal.current, - "description" => donation_goal.description, - "title" => donation_goal.title + "description" => donation_goal.description }, "relationships" => %{ "project" => %{ diff --git a/web/models/donation_goal.ex b/web/models/donation_goal.ex index fc5c9e76b..ed8a1e130 100644 --- a/web/models/donation_goal.ex +++ b/web/models/donation_goal.ex @@ -6,7 +6,6 @@ defmodule CodeCorps.DonationGoal do * amount - donation amount, in cents, needed to reach the goal * current - indicates if the goal is currently active * description - a longer, more informative description of the goal - * title - a short, but descriptive goal title """ use CodeCorps.Web, :model @@ -15,7 +14,6 @@ defmodule CodeCorps.DonationGoal do field :amount, :integer field :current, :boolean field :description, :string - field :title, :string belongs_to :project, CodeCorps.Project @@ -27,8 +25,8 @@ defmodule CodeCorps.DonationGoal do """ def create_changeset(struct, params \\ %{}) do struct - |> cast(params, [:amount, :current, :description, :project_id, :title]) - |> validate_required([:amount, :current, :description, :project_id, :title]) + |> cast(params, [:amount, :current, :description, :project_id]) + |> validate_required([:amount, :current, :description, :project_id]) |> assoc_constraint(:project) end @@ -37,7 +35,7 @@ defmodule CodeCorps.DonationGoal do """ def update_changeset(struct, params \\ %{}) do struct - |> cast(params, [:amount, :current, :description, :title]) - |> validate_required([:amount, :current, :description, :title]) + |> cast(params, [:amount, :current, :description]) + |> validate_required([:amount, :current, :description]) end end diff --git a/web/views/donation_goal_view.ex b/web/views/donation_goal_view.ex index b6a63934e..e9a99fdba 100644 --- a/web/views/donation_goal_view.ex +++ b/web/views/donation_goal_view.ex @@ -3,7 +3,7 @@ defmodule CodeCorps.DonationGoalView do use CodeCorps.Web, :view use JaSerializer.PhoenixView - attributes [:amount, :current, :description, :title] + attributes [:amount, :current, :description] has_one :project, serializer: CodeCorps.ProjectView end