From: Tom Hughes Date: Tue, 27 Feb 2024 20:53:24 +0000 (+0000) Subject: Add a system test to do an end-end test of changing email X-Git-Tag: live~753 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/47ef813f1fbb59136a77bf1d154ce4d136269458 Add a system test to do an end-end test of changing email --- diff --git a/test/system/user_email_change_test.rb b/test/system/user_email_change_test.rb new file mode 100644 index 000000000..eceb73416 --- /dev/null +++ b/test/system/user_email_change_test.rb @@ -0,0 +1,35 @@ +require "application_system_test_case" + +class UserEmailChangeTest < ApplicationSystemTestCase + include ActionMailer::TestHelper + + def setup + stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404) + end + + test "User can change their email address" do + user = create(:user) + sign_in_as(user) + + assert_emails 1 do + visit edit_account_path + fill_in "New Email Address", :with => "new_tester@example.com" + click_on "Save Changes" + assert_equal "new_tester@example.com", user.reload.new_email + end + + email = ActionMailer::Base.deliveries.first + assert_equal 1, email.to.count + assert_equal "new_tester@example.com", email.to.first + assert_match %r{/user/confirm-email\?confirm_string=[A-Za-z0-9-_%]+\s}, email.parts[0].parts[0].decoded + + if email.parts[0].parts[0].decoded =~ %r{(/user/confirm-email\?confirm_string=[A-Za-z0-9-_%]+)\s} + visit Regexp.last_match(1) + assert page.has_css?("body.accounts-edit") + end + + assert_equal "new_tester@example.com", user.reload.email + + ActionMailer::Base.deliveries.clear + end +end