Browse Source

wip

pull/1710/head
Jack S 3 years ago
parent
commit
7512f5fafc
  1. 6
      app/models/user.rb
  2. 26
      spec/models/user_spec.rb

6
app/models/user.rb

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

26
spec/models/user_spec.rb

@ -369,4 +369,30 @@ RSpec.describe User, type: :model do
end
end
end
describe "#send_data_protection_confirmation_reminder" do
context "when updating to dpo" do
let!(:user) { create(:user, is_dpo: false) }
it "sends the email" do
expect { user.update!(is_dpo: true) }.to enqueue_job(DataProtectionConfirmationMailer)
end
end
context "when updating to non dpo" do
let!(:user) { create(:user, is_dpo: true) }
it "does not send the email" do
expect { user.update!(is_dpo: false) }.not_to enqueue_job(DataProtectionConfirmationMailer)
end
end
context "when updating something else" do
let!(:user) { create(:user) }
it "does not send the email" do
expect { user.update!(name: "foobar") }.not_to enqueue_job(DataProtectionConfirmationMailer)
end
end
end
end

Loading…
Cancel
Save