|
6 | 6 | # (See `app/controllers/concerns/email_confirmation_handler.rb`) |
7 | 7 | # Here, we define "unconfirmable" as a user that is both unconfirmed and has no outstanding confirmation token |
8 | 8 | RSpec.describe 'Email Confirmation', type: :feature do |
9 | | - before(:each) do |
10 | | - @default_locale = I18n.default_locale |
11 | | - I18n.default_locale = :'en-CA' |
12 | | - end |
13 | | - |
14 | | - after(:each) do |
15 | | - I18n.default_locale = @default_locale |
16 | | - end |
17 | | - |
18 | 9 | scenario 'A user attempts to sign in via the "Sign In" button. However, they are unconfirmable.', :js do |
19 | | - # Setup |
20 | 10 | user = create(:user, :unconfirmable) |
21 | | - |
22 | | - # Actions |
23 | 11 | sign_in(user) |
24 | | - user.reload |
25 | | - |
26 | | - # Expectations |
27 | | - expectations_for_unconfirmable_user_after_sign_in_attempt(user) |
28 | | - |
29 | | - # Actions |
30 | | - sign_in(user) |
31 | | - |
32 | | - # Expectations |
33 | | - expect_request_new_confirmation_link_message |
34 | | - end |
35 | 12 |
|
36 | | - scenario 'A user attempts to sign in via the "Sign in with institutional or social ID" |
37 | | - button with an email that is not currently linked to any account. The chosen |
38 | | - SSO email matches an existing user account email. However, they are unconfirmable.', :js do |
39 | | - # Setup |
40 | | - Rails.application.env_config['devise.mapping'] = Devise.mappings[:user] |
41 | | - Rails.application.env_config['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] |
42 | | - user = create(:user, :unconfirmable, email: OmniAuth.config.mock_auth[:openid_connect][:info][:email]) |
43 | | - |
44 | | - # Actions |
45 | | - visit root_path |
46 | | - click_link 'Sign in with institutional or social ID' |
| 13 | + # A flash notice is displayed informing the user that a confirmation email has been sent |
| 14 | + expect(page.text).to have_text(I18n.t('devise.registrations.signed_up_but_unconfirmed')) |
| 15 | + # reload the user to check confirmation values |
47 | 16 | user.reload |
48 | 17 |
|
49 | | - # Expectations |
50 | | - expectations_for_unconfirmable_user_after_sign_in_attempt(user) |
51 | | - # An Identifier entry was not created |
52 | | - expect(Identifier.count).to be_zero |
53 | | - |
54 | | - # Actions |
55 | | - click_link 'Sign in with institutional or social ID' |
56 | | - |
57 | | - # Expectations |
58 | | - expect_request_new_confirmation_link_message |
59 | | - end |
60 | | - |
61 | | - private |
62 | | - |
63 | | - def expectations_for_unconfirmable_user_after_sign_in_attempt(user) |
64 | 18 | # The user remains unconfirmed |
65 | 19 | expect(user.confirmed?).to be(false) |
66 | 20 | # A confirmation_token now exists |
67 | 21 | expect(user.confirmation_token).to be_present |
68 | 22 | # The user is not signed in |
69 | 23 | expect(current_path).to eq(root_path) |
70 | | - # The correct flash message was rendered |
71 | | - expect_confirmation_link_has_been_sent_message |
72 | | - end |
73 | 24 |
|
74 | | - def expect_confirmation_link_has_been_sent_message |
75 | | - msg = 'A message with a confirmation link has been sent to your email address. ' \ |
76 | | - 'Please open the link to activate your account. ' \ |
77 | | - 'If you do not receive the confirmation email, please check your spam filter.' |
78 | | - expect(page.text).to have_text(msg) |
79 | | - end |
80 | | - |
81 | | - def expect_request_new_confirmation_link_message |
82 | | - msg = 'You need to confirm your account before continuing. ' \ |
83 | | - '(Click to request a new confirmation email)' |
84 | | - expect(page.text).to have_text(msg) |
| 25 | + sign_in(user) |
| 26 | + # A flash warning is displayed informing the user that they have to confirm their email |
| 27 | + expect(page.text).to have_text(I18n.t('devise.failure.unconfirmed')) |
85 | 28 | end |
86 | 29 | end |
0 commit comments