|
13 | 13 | expect(page).to have_text("Logged in as new_username") |
14 | 14 | end |
15 | 15 |
|
16 | | - def fill_in_username_fields(existing_password) |
| 16 | + def fill_in_username_fields(existing_password, username: "new_username") |
17 | 17 | within_fieldset("Change Username") do |
18 | | - fill_in("Username", with: "new_username") |
| 18 | + fill_in("Username", with: username) |
19 | 19 | fill_in("Existing password", with: existing_password) |
20 | 20 | end |
21 | 21 | end |
@@ -49,6 +49,29 @@ def fill_in_password_fields(existing_password, new_password) |
49 | 49 | expect(page).to have_text("Unable to update profile") |
50 | 50 | end |
51 | 51 |
|
| 52 | + def fill_in_mismatched_password_fields(existing_password) |
| 53 | + within_fieldset("Change Password") do |
| 54 | + fill_in("Existing password", with: existing_password) |
| 55 | + fill_in("New password", with: "new_password") |
| 56 | + fill_in("Password confirmation", with: "different_password") |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + it "rejects password change with mismatched confirmation" do |
| 61 | + fill_in_mismatched_password_fields(default_user.password) |
| 62 | + click_on("Update password") |
| 63 | + |
| 64 | + expect(page).to have_text("Unable to update password") |
| 65 | + end |
| 66 | + |
| 67 | + it "rejects username change when already taken" do |
| 68 | + create(:user, username: "taken_name") |
| 69 | + fill_in_username_fields(default_user.password, username: "taken_name") |
| 70 | + click_on("Update username") |
| 71 | + |
| 72 | + expect(page).to have_text("Unable to update profile") |
| 73 | + end |
| 74 | + |
52 | 75 | it "rejects password change with wrong existing password" do |
53 | 76 | fill_in_password_fields("wrong_password", "new_password") |
54 | 77 | click_on("Update password") |
|
0 commit comments