Skip to content

Commit

Permalink
Add a system test to do an end-end test of changing email
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Feb 27, 2024
1 parent 085d8eb commit 47ef813
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/system/user_email_change_test.rb
Original file line number Diff line number Diff line change
@@ -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 => "[email protected]"
click_on "Save Changes"
assert_equal "[email protected]", user.reload.new_email
end

email = ActionMailer::Base.deliveries.first
assert_equal 1, email.to.count
assert_equal "[email protected]", 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 "[email protected]", user.reload.email

ActionMailer::Base.deliveries.clear
end
end

0 comments on commit 47ef813

Please sign in to comment.