Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions blueprint/api.apib
Original file line number Diff line number Diff line change
Expand Up @@ -2221,20 +2221,18 @@ 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.

## 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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/controllers/donation_goal_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions test/models/donation_goal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ 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?
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[: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
Expand All @@ -28,16 +27,15 @@ 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)

refute changeset.valid?
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
1 change: 0 additions & 1 deletion test/support/factories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/views/donation_goal_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => %{
Expand Down
10 changes: 4 additions & 6 deletions web/models/donation_goal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion web/views/donation_goal_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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