Skip to content

Commit

Permalink
Merge pull request #816 from jessica-jordan/code-corps-api#692/add-va…
Browse files Browse the repository at this point in the history
…lidation-to-donation-goals-pos-numbers-only

Code corps api#692/add validation to donation goals: positive numbers only
  • Loading branch information
joshsmith committed Jun 4, 2017
2 parents 3e670f6 + 85684d0 commit 6a6d6aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/models/donation_goal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ defmodule CodeCorps.DonationGoalTest do
refute changeset.valid?
changeset |> assert_error_message(:project, "does not exist")
end

test "amount must not be negative" do
attrs = %{amount: -100, description: "Cashback for donators", project_id: 2}
donation_goal = insert(:donation_goal)
changeset = DonationGoal.create_changeset(donation_goal, attrs)

refute changeset.valid?
changeset |> assert_error_message(:amount, "must be greater than %{number}")
end
end

describe "&update_changeset/2" do
Expand Down
1 change: 1 addition & 0 deletions web/models/donation_goal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule CodeCorps.DonationGoal do
struct
|> cast(params, [:amount, :description, :project_id])
|> validate_required([:amount, :description, :project_id])
|> validate_number(:amount, greater_than: 0)
|> assoc_constraint(:project)
end

Expand Down

0 comments on commit 6a6d6aa

Please sign in to comment.