Don't check the database during system tests
As mentioned in commits likea586ba806,a7664ad81,006128da5,b41fbfa52andc480cdd91, 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. So, just like we did a few commits ago with tests that reloaded records, we're modifying the tests to check the results of user interactions from the point of view of the users. Also note we aren't changing tests with the `:no_js` tag, since these tests don't run a real browser in a separate process. In the future, we should also change most of these tests so they don't access the database and they use a real browser. Finally, note that one of the tests we're changing in the shared `notifiable_in_app` file did not check the database content, but we're also changing it for consistency.
This commit is contained in:
@@ -4,7 +4,7 @@ describe "Users" do
|
||||
scenario "Create a level 3 user with email from scratch" do
|
||||
login_as_manager
|
||||
visit management_document_verifications_path
|
||||
fill_in "document_verification_document_number", with: "12345678Z"
|
||||
fill_in "Document number", with: "12345678Z"
|
||||
click_button "Check document"
|
||||
|
||||
expect(page).to have_content "Please introduce the email used on the account"
|
||||
@@ -20,12 +20,11 @@ describe "Users" do
|
||||
expect(page).to have_content "We have sent an email"
|
||||
expect(page).not_to have_content "Autogenerated password is"
|
||||
|
||||
user = User.find_by(email: "pepe@gmail.com")
|
||||
visit management_document_verifications_path
|
||||
fill_in "Document number", with: "12345678Z"
|
||||
click_button "Check document"
|
||||
|
||||
expect(user).to be_level_three_verified
|
||||
expect(user).to be_residence_verified
|
||||
expect(user).not_to be_confirmed
|
||||
expect(user.date_of_birth).to have_content Date.new(1980, 12, 31)
|
||||
expect(page).to have_content "This user account is already verified"
|
||||
|
||||
sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1]
|
||||
visit user_confirmation_path(confirmation_token: sent_token)
|
||||
@@ -62,14 +61,22 @@ describe "Users" do
|
||||
click_button "Create user"
|
||||
|
||||
expect(page).not_to have_content "We have sent an email"
|
||||
expect(page).to have_content "Autogenerated password is"
|
||||
generated_password = find("p", text: "Autogenerated password is").find("b").text
|
||||
|
||||
user = User.find_by(username: "Kelly Sue")
|
||||
visit management_document_verifications_path
|
||||
fill_in "Document number", with: "12345678Z"
|
||||
click_button "Check document"
|
||||
|
||||
expect(user).to be_level_three_verified
|
||||
expect(user).to be_residence_verified
|
||||
expect(user).to be_confirmed
|
||||
expect(user.date_of_birth).to have_content Date.new(1980, 12, 31)
|
||||
expect(page).to have_content "This user account is already verified"
|
||||
|
||||
logout
|
||||
login_through_form_with("Kelly Sue", password: generated_password)
|
||||
|
||||
expect(page).to have_content "You have been signed in successfully."
|
||||
|
||||
visit account_path
|
||||
|
||||
expect(page).to have_content "Account verified"
|
||||
end
|
||||
|
||||
scenario "Delete a level 2 user account from document verification page" do
|
||||
|
||||
Reference in New Issue
Block a user