From 185dee9679dc48259dc72494f08d9a9d7287bb7d Mon Sep 17 00:00:00 2001
From: Osman Latif
<%= t('devise.registrations.close_window') %>
- <% if FeatureManagement.enable_load_testing_mode? %> + <% if FeatureManagement.enable_load_testing_mode? && EmailAddress.find_with_email(email) %> <%= link_to( 'CONFIRM NOW', - sign_up_create_email_confirmation_url(confirmation_token: EmailAddress.find_with_email(email)&.confirmation_token), + sign_up_create_email_confirmation_url(confirmation_token: EmailAddress.find_with_email(email).confirmation_token), id: 'confirm-now', ) %> <% end %> diff --git a/app/views/users/emails/verify.html.erb b/app/views/users/emails/verify.html.erb index 20138508ef6..fa4af394dc7 100644 --- a/app/views/users/emails/verify.html.erb +++ b/app/views/users/emails/verify.html.erb @@ -25,7 +25,7 @@<%= t('notices.use_diff_email.text_html', link_html: link_to(t('notices.use_diff_email.link'), add_email_path)) %>
<%= t('devise.registrations.close_window') %>
-<% if FeatureManagement.enable_load_testing_mode? %> +<% if FeatureManagement.enable_load_testing_mode? && EmailAddress.find_with_email(email) %> <%= link_to( 'CONFIRM NOW', sign_up_create_email_confirmation_url(confirmation_token: EmailAddress.find_with_email(email).confirmation_token), diff --git a/spec/views/sign_up/emails/show.html.erb_spec.rb b/spec/views/sign_up/emails/show.html.erb_spec.rb index ae928947cb1..10f79b8894d 100644 --- a/spec/views/sign_up/emails/show.html.erb_spec.rb +++ b/spec/views/sign_up/emails/show.html.erb_spec.rb @@ -1,8 +1,9 @@ require 'rails_helper' RSpec.describe 'sign_up/emails/show.html.erb' do + let(:email) { 'foo@bar.com' } before do - allow(view).to receive(:email).and_return('foo@bar.com') + allow(view).to receive(:email).and_return(email) @resend_email_confirmation_form = ResendEmailConfirmationForm.new end @@ -23,4 +24,47 @@ expect(rendered).to have_button(t('links.resend')) end + + context 'when enable_load_testing_mode? is true and email address found' do + before do + allow(FeatureManagement).to receive(:enable_load_testing_mode?).and_return(true) + email_address = instance_double(EmailAddress, confirmation_token: 'some_token') + allow(EmailAddress).to receive(:find_with_email).with(email).and_return(email_address) + + render + end + + it 'generates the correct link' do + expect(rendered).to have_link( + 'CONFIRM NOW', + href: sign_up_create_email_confirmation_url(confirmation_token: 'some_token'), + id: 'confirm-now', + ) + end + end + + context 'when enable_load_testing_mode? is false' do + before do + allow(FeatureManagement).to receive(:enable_load_testing_mode?).and_return(false) + + render + end + + it 'does not generate the link' do + expect(rendered).not_to have_link('CONFIRM NOW', href: sign_up_create_email_confirmation_url) + end + end + + context 'when email address not found' do + before do + allow(FeatureManagement).to receive(:enable_load_testing_mode?).and_return(true) + allow(EmailAddress).to receive(:find_with_email).with(email).and_return(nil) + + render + end + + it 'does not generate the link' do + expect(rendered).not_to have_link('CONFIRM NOW', href: sign_up_create_email_confirmation_url) + end + end end diff --git a/spec/views/users/emails/verify.html.erb_spec.rb b/spec/views/users/emails/verify.html.erb_spec.rb new file mode 100644 index 00000000000..ae8a611d331 --- /dev/null +++ b/spec/views/users/emails/verify.html.erb_spec.rb @@ -0,0 +1,70 @@ +require 'rails_helper' + +RSpec.describe 'users/emails/verify.html.erb' do + let(:email) { 'foo@bar.com' } + before do + allow(view).to receive(:email).and_return(email) + @resend_email_confirmation_form = ResendEmailConfirmationForm.new + end + + it 'has a localized title' do + expect(view).to receive(:title).with(t('titles.verify_email')) + + render + end + + it 'has a localized header' do + render + + expect(rendered).to have_selector('h1', text: t('headings.verify_email')) + end + + it 'contains link to resend confirmation page' do + render + + expect(rendered).to have_button(t('links.resend')) + end + + context 'when enable_load_testing_mode? is true and email address found' do + before do + allow(FeatureManagement).to receive(:enable_load_testing_mode?).and_return(true) + email_address = instance_double(EmailAddress, confirmation_token: 'some_token') + allow(EmailAddress).to receive(:find_with_email).with(email).and_return(email_address) + + render + end + + it 'generates the correct link' do + expect(rendered).to have_link( + 'CONFIRM NOW', + href: sign_up_create_email_confirmation_url(confirmation_token: 'some_token'), + id: 'confirm-now', + ) + end + end + + context 'when enable_load_testing_mode? is false' do + before do + allow(FeatureManagement).to receive(:enable_load_testing_mode?).and_return(false) + + render + end + + it 'does not generate the link' do + expect(rendered).not_to have_link('CONFIRM NOW', href: sign_up_create_email_confirmation_url) + end + end + + context 'when email address not found' do + before do + allow(FeatureManagement).to receive(:enable_load_testing_mode?).and_return(true) + allow(EmailAddress).to receive(:find_with_email).with(email).and_return(nil) + + render + end + + it 'does not generate the link' do + expect(rendered).not_to have_link('CONFIRM NOW', href: sign_up_create_email_confirmation_url) + end + end +end From a607ab253a8b7995721597bf6a2366cc1abdac9e Mon Sep 17 00:00:00 2001 From: Osman Latif