From aa8d5ad7050f3657e84bfd97c61bc3d86da803fa Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 16 Aug 2024 11:47:48 +0100 Subject: [PATCH] Discard email changes when deactivating user --- app/models/user.rb | 1 + spec/requests/users_controller_spec.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index c79ceb0d9..58e806bc5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -142,6 +142,7 @@ class User < ApplicationRecord sign_in_count: 0, initial_confirmation_sent: false, reactivate_with_organisation:, + unconfirmed_email: nil, ) end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 8e87f7f28..c2240a77d 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -434,7 +434,7 @@ RSpec.describe UsersController, type: :request do context "when user is signed in as a data coordinator" do let(:user) { create(:user, :data_coordinator, email: "coordinator@example.com", organisation: create(:organisation, :without_dpc)) } - let!(:other_user) { create(:user, organisation: user.organisation, name: "filter name", email: "filter@example.com") } + let!(:other_user) { create(:user, organisation: user.organisation, name: "filter name", email: "filter@example.com", unconfirmed_email: "email@something.com") } before do sign_in user @@ -885,6 +885,11 @@ RSpec.describe UsersController, type: :request do expect { patch "/users/#{other_user.id}", headers:, params: } .to change { other_user.reload.active }.from(true).to(false) end + + it "discards unconfirmed email" do + expect { patch "/users/#{other_user.id}", headers:, params: } + .to change { other_user.reload.unconfirmed_email }.from("email@something.com").to(nil) + end end context "and tries to activate deactivated user" do