Skip to content

Commit

Permalink
Allow setting user state to 'signed_up_donating' on registration
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Mar 22, 2017
1 parent 7521582 commit 83ca182
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions test/models/user_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ defmodule CodeCorps.UserTest do
refute changeset.valid?
assert_error_message(changeset, :username, "has already been taken")
end

test "allows setting state to 'signed_up_donating'" do
attrs = @valid_attrs |> Map.put(:state, "signed_up_donating")
changeset = User.registration_changeset(%User{}, attrs)
assert changeset.valid?
assert changeset |> Ecto.Changeset.get_change(:state) == "signed_up_donating"

attrs = @valid_attrs |> Map.put(:state, "selected_skills")
changeset = User.registration_changeset(%User{}, attrs)
refute changeset.valid?
end
end

describe "update_changeset" do
Expand Down
6 changes: 3 additions & 3 deletions web/models/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ defmodule CodeCorps.User do
def registration_changeset(struct, params) do
struct
|> changeset(params)
|> cast(params, [:password, :username])
|> validate_required(:password)
|> validate_required(:username)
|> cast(params, [:password, :username, :state])
|> validate_required([:password, :username])
|> validate_length(:password, min: 6)
|> validate_length(:username, min: 1, max: 39)
|> validate_inclusion(:state, ["signed_up_donating"])
|> validate_slug(:username)
|> unique_constraint(:username, name: :users_lower_username_index)
|> unique_constraint(:email)
Expand Down

0 comments on commit 83ca182

Please sign in to comment.