diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 22b93d2d6..62670188f 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -26,11 +26,5 @@ FactoryBot.define do transient do old_user_id { SecureRandom.uuid } end - - after(:create) do |user, evaluator| - FactoryBot.create(:legacy_user, old_user_id: evaluator.old_user_id, user:) - - user.reload - end end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index e3335c762..169465cb1 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -594,7 +594,7 @@ RSpec.describe "User Features" do end before do - other_user.update!(initial_confirmation_sent: true, last_sign_in_at: nil) + other_user.update!(initial_confirmation_sent: true, last_sign_in_at: nil, old_user_id: "old-user-id") allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in(user) visit(user_path(other_user)) diff --git a/spec/mailers/resend_invitation_mailer_spec.rb b/spec/mailers/resend_invitation_mailer_spec.rb index a5eadad20..2b76484c3 100644 --- a/spec/mailers/resend_invitation_mailer_spec.rb +++ b/spec/mailers/resend_invitation_mailer_spec.rb @@ -41,6 +41,7 @@ RSpec.describe ResendInvitationMailer do end it "sends an initial invitation" do + FactoryBot.create(:legacy_user, old_user_id: new_active_migrated_user.old_user_id, user: new_active_migrated_user) expect(notify_client).to receive(:send_email).with(email_address: "new_active_migrated_user@example.com", template_id: User::BETA_ONBOARDING_TEMPLATE_ID, personalisation:).once described_class.new.resend_invitation_email(new_active_migrated_user) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 05a581ee8..edb998ac3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -114,6 +114,7 @@ RSpec.describe User, type: :model do end it "can have one or more legacy users" do + FactoryBot.create(:legacy_user, old_user_id: user.old_user_id, user:) expect(user.legacy_users.size).to eq(1) end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 68f69d9f2..a41db9791 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -1648,6 +1648,7 @@ RSpec.describe OrganisationsController, type: :request do allow(notify_client).to receive(:send_email).and_return(true) user_to_reactivate = create(:user, :data_coordinator, organisation:, active: false, reactivate_with_organisation: true) + FactoryBot.create(:legacy_user, old_user_id: user_to_reactivate.old_user_id, user: user_to_reactivate) user_not_to_reactivate = create(:user, :data_coordinator, organisation:, active: false, reactivate_with_organisation: false) patch "/organisations/#{organisation.id}", headers:, params: end