Don't destroy records during a system test

As mentioned in commits like a586ba806, a7664ad81, 006128da5, b41fbfa52
and c480cdd91, accessing the database after starting the browser with
the `visit` method sometimes results in database corruption and failing
tests on our CI due to the process running the test accessing the
database after the process running the browser has started.

IMHO this is also a bad practice for system tests, since these tests
should be checking what users experience.

In this case, however, I haven't found a way to destroy the VerifiedUser
record using the interface, so we're stubbing `VerifiedUser` instead.
Note we can't stub it since the beginning of the test because we're
testing what happens when clicking the "Send code" button doesn't work,
and we wouldn't be able to access the page containing the "Send code" if
we stubbed `VerifiedUser` since the beginning of the test.
This commit is contained in:
Javi Martín
2025-03-14 04:10:28 +01:00
parent a6d470ded6
commit 92fc45cbb4

View File

@@ -47,16 +47,18 @@ describe "Verify email" do
document_number: "12345678Z",
document_type: "dni")
verified_user = create(:verified_user,
create(:verified_user,
document_number: "12345678Z",
document_type: "dni",
email: "rock@example.com")
login_as(user)
visit verified_user_path
verified_user.destroy!
expect(page).to have_button "Send code"
allow(VerifiedUser).to receive(:by_user).and_return(VerifiedUser.none)
click_button "Send code"
expect(page).to have_content "There was a problem with sending an email to your account"