File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -132,4 +132,16 @@ defmodule CodeCorps.UserTest do
132132 assert message == "invalid transition yehaww from signed_up"
133133 end
134134 end
135+
136+ test "reset_password_changeset with valid passwords" do
137+ changeset = User . reset_password_changeset ( % User { } , % { password: "foobar" , password_confirmation: "foobar" } )
138+ assert changeset . valid?
139+ assert changeset . changes . encrypted_password
140+ end
141+
142+ test "reset_password_changeset with invalid passwords generates message" do
143+ changeset = User . reset_password_changeset ( % User { } , % { password: "wat" , password_confirmation: "foobar" } )
144+ refute changeset . valid?
145+ assert error_message ( changeset , :password_confirmation ) == "passwords do not match"
146+ end
135147end
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ defmodule CodeCorps.User do
2525 field :first_name , :string
2626 field :last_name , :string
2727 field :password , :string , virtual: true
28+ field :password_confirmation , :string , virtual: true
2829 field :twitter , :string
2930 field :username , :string
3031 field :website , :string
@@ -96,6 +97,13 @@ defmodule CodeCorps.User do
9697 |> apply_state_transition ( struct )
9798 end
9899
100+ def reset_password_changeset ( struct , params ) do
101+ struct
102+ |> cast ( params , [ :password , :password_confirmation ] )
103+ |> validate_confirmation ( :password , message: "passwords do not match" )
104+ |> put_pass_hash
105+ end
106+
99107 def apply_state_transition ( changeset , % { state: current_state } ) do
100108 state_transition = get_field ( changeset , :state_transition )
101109 next_state = CodeCorps.Transition.UserState . next ( current_state , state_transition )
You can’t perform that action at this time.
0 commit comments