From ea1abf566254c33674642acf65f2599dd1a37bce Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Fri, 8 Aug 2025 16:33:19 +0300 Subject: [PATCH] fix test email --- lib/accounts.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/accounts.rb b/lib/accounts.rb index 898051fc..6153111b 100644 --- a/lib/accounts.rb +++ b/lib/accounts.rb @@ -53,8 +53,11 @@ module Accounts ApplicationRecord.transaction do account.testing_accounts << testing_account + original_email = account.users.order(:id).first.email + test_email = generate_unique_test_email(original_email) + testing_account.users.create!( - email: account.users.order(:id).first.email.sub('@', '+test@'), + email: test_email, first_name: 'Testing', last_name: 'Environment', password: SecureRandom.hex, @@ -63,6 +66,22 @@ module Accounts end end + def generate_unique_test_email(original_email) + base_email = original_email.sub('@', '+test@') + + return base_email unless User.exists?(email: base_email) + + (1..3).each do |i| + test_email = original_email.sub('@', "+test#{i}@") + + return test_email unless User.exists?(email: test_email) + end + + timestamp = Time.current.to_i + + original_email.sub('@', "+test#{timestamp}@") + end + def create_default_template(account) template = Template.find(1)