From 185dee9679dc48259dc72494f08d9a9d7287bb7d Mon Sep 17 00:00:00 2001 From: Osman Latif Date: Fri, 28 Jul 2023 10:45:59 -0500 Subject: [PATCH 1/4] LG-10313: 500 error fixes [skip changelog] --- app/views/sign_up/emails/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/sign_up/emails/show.html.erb b/app/views/sign_up/emails/show.html.erb index 033e2b1948d..e8dd0df30d0 100644 --- a/app/views/sign_up/emails/show.html.erb +++ b/app/views/sign_up/emails/show.html.erb @@ -38,7 +38,7 @@ <% if FeatureManagement.enable_load_testing_mode? %> <%= 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 %> From f43a99ba0c406d559c94ce28b22d73632b50b5a3 Mon Sep 17 00:00:00 2001 From: Osman Latif Date: Fri, 28 Jul 2023 14:31:57 -0500 Subject: [PATCH 2/4] rspec and changes --- app/views/sign_up/emails/show.html.erb | 4 +- app/views/users/emails/verify.html.erb | 2 +- .../sign_up/emails/show.html.erb_spec.rb | 46 +++++++++++- .../users/emails/verify.html.erb_spec.rb | 70 +++++++++++++++++++ 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 spec/views/users/emails/verify.html.erb_spec.rb diff --git a/app/views/sign_up/emails/show.html.erb b/app/views/sign_up/emails/show.html.erb index e8dd0df30d0..efb53bdb7d6 100644 --- a/app/views/sign_up/emails/show.html.erb +++ b/app/views/sign_up/emails/show.html.erb @@ -35,10 +35,10 @@

<%= 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 Date: Fri, 28 Jul 2023 14:57:17 -0500 Subject: [PATCH 3/4] removing extra --- spec/views/sign_up/emails/show.html.erb_spec.rb | 1 - spec/views/users/emails/verify.html.erb_spec.rb | 1 - 2 files changed, 2 deletions(-) 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 10f79b8894d..5f537d74f81 100644 --- a/spec/views/sign_up/emails/show.html.erb_spec.rb +++ b/spec/views/sign_up/emails/show.html.erb_spec.rb @@ -58,7 +58,6 @@ 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 diff --git a/spec/views/users/emails/verify.html.erb_spec.rb b/spec/views/users/emails/verify.html.erb_spec.rb index ae8a611d331..2bfb1f1023e 100644 --- a/spec/views/users/emails/verify.html.erb_spec.rb +++ b/spec/views/users/emails/verify.html.erb_spec.rb @@ -58,7 +58,6 @@ 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 From 4e957a3be590f22478fff0058c2ab1ac5aec6f82 Mon Sep 17 00:00:00 2001 From: Osman Latif Date: Fri, 28 Jul 2023 15:03:26 -0500 Subject: [PATCH 4/4] removing stud actual factory --- spec/views/sign_up/emails/show.html.erb_spec.rb | 3 +-- spec/views/users/emails/verify.html.erb_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) 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 5f537d74f81..af01a3d1536 100644 --- a/spec/views/sign_up/emails/show.html.erb_spec.rb +++ b/spec/views/sign_up/emails/show.html.erb_spec.rb @@ -28,8 +28,7 @@ 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) + create(:email_address, confirmation_token: 'some_token', email: email) render end diff --git a/spec/views/users/emails/verify.html.erb_spec.rb b/spec/views/users/emails/verify.html.erb_spec.rb index 2bfb1f1023e..61e91859daf 100644 --- a/spec/views/users/emails/verify.html.erb_spec.rb +++ b/spec/views/users/emails/verify.html.erb_spec.rb @@ -28,8 +28,7 @@ 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) + create(:email_address, confirmation_token: 'some_token', email: email) render end