Browse Source

Send confirmation email to user

pull/1710/head
Jack S 3 years ago
parent
commit
adb34b0033
  1. 7
      app/models/user.rb
  2. 21
      spec/models/user_spec.rb

7
app/models/user.rb

@ -21,7 +21,7 @@ class User < ApplicationRecord
validates :password, confirmation: { if: :password_required? } validates :password, confirmation: { if: :password_required? }
validates :password, length: { within: Devise.password_length, allow_blank: true } validates :password, length: { within: Devise.password_length, allow_blank: true }
after_update :send_data_protection_confirmation_reminder, if: :is_dpo_changed? after_validation :send_data_protection_confirmation_reminder, if: :is_dpo_changed?
validates :organisation_id, presence: true validates :organisation_id, presence: true
@ -186,10 +186,11 @@ protected
private private
def send_data_protection_confirmation_reminder def send_data_protection_confirmation_reminder
# binding.pry return unless FeatureToggle.new_data_protection_confirmation?
return unless persisted?
return unless is_dpo_changed? return unless is_dpo_changed?
return unless is_dpo? return unless is_dpo?
DataProtectionConfirmationMailer.send_confirmation_email(user).deliver_later DataProtectionConfirmationMailer.send_confirmation_email(self).deliver_later
end end
end end

21
spec/models/user_spec.rb

@ -375,7 +375,22 @@ RSpec.describe User, type: :model do
let!(:user) { create(:user, is_dpo: false) } let!(:user) { create(:user, is_dpo: false) }
it "sends the email" do it "sends the email" do
expect { user.update!(is_dpo: true) }.to enqueue_job(DataProtectionConfirmationMailer) expect { user.update!(is_dpo: true) }.to enqueue_job(ActionMailer::MailDeliveryJob).with(
"DataProtectionConfirmationMailer",
"send_confirmation_email",
"deliver_now",
args: [user],
)
end
context "when feature flag disabled" do
before do
allow(FeatureToggle).to receive(:new_data_protection_confirmation?).and_return(false)
end
it "does not send the email" do
expect { user.update!(is_dpo: true) }.not_to enqueue_job(ActionMailer::MailDeliveryJob)
end
end end
end end
@ -383,7 +398,7 @@ RSpec.describe User, type: :model do
let!(:user) { create(:user, is_dpo: true) } let!(:user) { create(:user, is_dpo: true) }
it "does not send the email" do it "does not send the email" do
expect { user.update!(is_dpo: false) }.not_to enqueue_job(DataProtectionConfirmationMailer) expect { user.update!(is_dpo: false) }.not_to enqueue_job(ActionMailer::MailDeliveryJob)
end end
end end
@ -391,7 +406,7 @@ RSpec.describe User, type: :model do
let!(:user) { create(:user) } let!(:user) { create(:user) }
it "does not send the email" do it "does not send the email" do
expect { user.update!(name: "foobar") }.not_to enqueue_job(DataProtectionConfirmationMailer) expect { user.update!(name: "foobar") }.not_to enqueue_job(ActionMailer::MailDeliveryJob)
end end
end end
end end

Loading…
Cancel
Save