Skip to content

Commit dae4764

Browse files
Check for what the user sees before checking background changes
This reduces race condition issues by checking what happens in the browser first.
1 parent ea5e14a commit dae4764

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

spec/system/volunteers/edit_spec.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,15 @@
140140

141141
fill_in "Email", with: "newemail@example.com"
142142
click_on "Submit"
143-
volunteer.reload
143+
144+
expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent."
145+
expect(page).to have_field("Email", with: old_email)
146+
expect(volunteer.reload.unconfirmed_email).to eq("newemail@example.com")
144147

145148
expect(ActionMailer::Base.deliveries.count).to eq(1)
146149
expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message)
147150
expect(ActionMailer::Base.deliveries.first.body.encoded)
148151
.to match("Click here to confirm your email")
149-
150-
expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent."
151-
expect(page).to have_field("Email", with: old_email)
152-
expect(volunteer.unconfirmed_email).to eq("newemail@example.com")
153152
end
154153

155154
it "succesfully displays the new email once the user confirms" do
@@ -481,6 +480,8 @@
481480
uncheck "with_cc"
482481
click_on "Send Reminder"
483482

483+
expect(page).to have_content("Reminder sent to volunteer")
484+
484485
expect(ActionMailer::Base.deliveries.count).to eq(1)
485486
expect(ActionMailer::Base.deliveries.first.cc).to be_empty
486487
end
@@ -496,6 +497,8 @@
496497
check "with_cc"
497498
click_on "Send Reminder"
498499

500+
expect(page).to have_content("Reminder sent to volunteer")
501+
499502
expect(ActionMailer::Base.deliveries.count).to eq(1)
500503
expect(ActionMailer::Base.deliveries.first.cc).to include(volunteer.supervisor.email)
501504
end
@@ -511,6 +514,8 @@
511514
check "with_cc"
512515
click_on "Send Reminder"
513516

517+
expect(page).to have_content("Reminder sent to volunteer")
518+
514519
expect(ActionMailer::Base.deliveries.count).to eq(1)
515520
expect(ActionMailer::Base.deliveries.first.cc).to be_empty
516521
end
@@ -530,6 +535,8 @@
530535

531536
click_on "Send Reminder"
532537

538+
expect(page).to have_content("Reminder sent to volunteer")
539+
533540
expect(ActionMailer::Base.deliveries.count).to eq(1)
534541
end
535542

@@ -543,6 +550,8 @@
543550
check "with_cc"
544551
click_on "Send Reminder"
545552

553+
expect(page).to have_content("Reminder sent to volunteer")
554+
546555
expect(ActionMailer::Base.deliveries.count).to eq(1)
547556
expect(ActionMailer::Base.deliveries.first.cc).to include(volunteer.supervisor.email)
548557
expect(ActionMailer::Base.deliveries.first.cc).to include(admin.email)

0 commit comments

Comments
 (0)