From 8f91b39603d8b85e371fb29d3c3afd780e4a87e2 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 2 Feb 2022 18:35:56 +0000 Subject: [PATCH] Devise token stubs --- spec/features/organisation_spec.rb | 8 +++++--- spec/features/user_spec.rb | 8 +++++--- spec/requests/auth/passwords_controller_spec.rb | 4 +++- spec/requests/users_controller_spec.rb | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index aeebc125b..1eb906212 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -8,11 +8,13 @@ RSpec.describe "User Features" do let(:set_password_template_id) { DeviseNotifyMailer::SET_PASSWORD_TEMPLATE_ID } let(:notify_client) { instance_double(Notifications::Client) } let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } before do - allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client) - allow_any_instance_of(DeviseNotifyMailer).to receive(:host).and_return("test.com") - allow_any_instance_of(User).to receive(:set_reset_password_token).and_return(reset_password_token) + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(devise_notify_mailer).to receive(:host).and_return("test.com") + allow(Devise.token_generator).to receive(:generate).and_return(reset_password_token) allow(notify_client).to receive(:send_email).and_return(true) sign_in user end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index ed022868c..10b091d37 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -6,12 +6,14 @@ RSpec.describe "User Features" do let(:reset_password_template_id) { DeviseNotifyMailer::RESET_PASSWORD_TEMPLATE_ID } let(:notify_client) { instance_double(Notifications::Client) } let(:reset_password_token) { "MCDH5y6Km-U7CFPgAMVS" } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } before do - allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client) - allow_any_instance_of(DeviseNotifyMailer).to receive(:host).and_return("test.com") + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(devise_notify_mailer).to receive(:host).and_return("test.com") allow(notify_client).to receive(:send_email).and_return(true) - allow_any_instance_of(User).to receive(:set_reset_password_token).and_return(reset_password_token) + allow(Devise.token_generator).to receive(:generate).and_return(reset_password_token) end context "when the user navigates to case logs" do diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 23a4b23d3..3ee41afee 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -5,9 +5,11 @@ RSpec.describe Auth::PasswordsController, type: :request do let(:params) { { user: { email: email } } } let(:page) { Capybara::Node::Simple.new(response.body) } let(:notify_client) { instance_double(Notifications::Client) } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } before do - allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client) + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) allow(notify_client).to receive(:send_email).and_return(true) end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 6b4af4d55..abd1adb67 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -8,9 +8,11 @@ RSpec.describe UsersController, type: :request do let(:new_value) { "new test name" } let(:params) { { id: user.id, user: { name: new_value } } } let(:notify_client) { instance_double(Notifications::Client) } + let(:devise_notify_mailer) { DeviseNotifyMailer.new } before do - allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client) + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) allow(notify_client).to receive(:send_email).and_return(true) end