]> git.openstreetmap.org Git - rails.git/blob - test/system/user_email_change_test.rb
Bump osm-community-index from 5.6.3 to 5.7.0
[rails.git] / test / system / user_email_change_test.rb
1 require "application_system_test_case"
2
3 class UserEmailChangeTest < ApplicationSystemTestCase
4   include ActionMailer::TestHelper
5
6   def setup
7     stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
8   end
9
10   test "User can change their email address" do
11     user = create(:user)
12     sign_in_as(user)
13
14     assert_emails 1 do
15       visit edit_account_path
16       fill_in "New Email Address", :with => "new_tester@example.com"
17       click_on "Save Changes"
18       assert_equal "new_tester@example.com", user.reload.new_email
19     end
20
21     email = ActionMailer::Base.deliveries.first
22     assert_equal 1, email.to.count
23     assert_equal "new_tester@example.com", email.to.first
24     assert_match %r{/user/confirm-email\?confirm_string=[A-Za-z0-9\-_%]+\s}, email.parts[0].parts[0].decoded
25
26     if email.parts[0].parts[0].decoded =~ %r{(/user/confirm-email\?confirm_string=[A-Za-z0-9\-_%]+)\s}
27       visit Regexp.last_match(1)
28       assert page.has_css?("body.accounts-edit")
29     end
30
31     assert_equal "new_tester@example.com", user.reload.email
32
33     ActionMailer::Base.deliveries.clear
34   end
35 end