File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,13 @@ def update
37
37
38
38
user = current_user
39
39
40
- if !user . authenticate ( params [ :user ] [ :password_challenge ] )
40
+ if user . password_digest_was . present? && !user . authenticate ( params [ :user ] [ :password_challenge ] )
41
41
flash . now [ :error ] = "Incorrect password"
42
42
return render Users ::Registrations ::EditView . new ( user : user ) , status : :unprocessable_entity
43
43
end
44
44
45
45
if !user . update ( update_user_params )
46
+ flash . now [ :error ] = user . errors . full_messages . to_sentence
46
47
return render Users ::Registrations ::EditView . new ( user : user ) , status : :unprocessable_entity
47
48
end
48
49
Original file line number Diff line number Diff line change 173
173
expect ( flash . now [ :error ] ) . to eq ( "Incorrect password" )
174
174
expect ( response ) . to have_http_status ( :unprocessable_entity )
175
175
end
176
+
177
+ it "allows for subscriber setting password first time" do
178
+ user = FactoryBot . create ( :user , :confirmed , :subscriber )
179
+ login_user ( user )
180
+
181
+ put users_registration_path ,
182
+ params : { user : { password : "password" , password_confirmation : "password" } }
183
+
184
+ expect ( response ) . to redirect_to ( users_dashboard_path )
185
+ expect ( flash [ :notice ] ) . to eq ( "Account updated" )
186
+ end
187
+
188
+ it "disallows for subscriber setting password first time without password confirmation" do
189
+ user = FactoryBot . create ( :user , :confirmed , :subscriber )
190
+ login_user ( user )
191
+
192
+ put users_registration_path ,
193
+ params : { user : { password : "password" , password_confirmation : "wrongpassword" } }
194
+
195
+ expect ( flash . now [ :error ] ) . to eq ( "Password confirmation doesn't match Password" )
196
+ expect ( response ) . to have_http_status ( :unprocessable_entity )
197
+ end
176
198
end
177
199
end
You can’t perform that action at this time.
0 commit comments