Browse Source

Discard email changes when deactivating user

pull/2587/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
aa8d5ad705
  1. 1
      app/models/user.rb
  2. 7
      spec/requests/users_controller_spec.rb

1
app/models/user.rb

@ -142,6 +142,7 @@ class User < ApplicationRecord
sign_in_count: 0, sign_in_count: 0,
initial_confirmation_sent: false, initial_confirmation_sent: false,
reactivate_with_organisation:, reactivate_with_organisation:,
unconfirmed_email: nil,
) )
end end

7
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 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(: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 before do
sign_in user sign_in user
@ -885,6 +885,11 @@ RSpec.describe UsersController, type: :request do
expect { patch "/users/#{other_user.id}", headers:, params: } expect { patch "/users/#{other_user.id}", headers:, params: }
.to change { other_user.reload.active }.from(true).to(false) .to change { other_user.reload.active }.from(true).to(false)
end 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 end
context "and tries to activate deactivated user" do context "and tries to activate deactivated user" do

Loading…
Cancel
Save