From bcbb2d2eb6d1c80525682703df87a628a3bcc55f Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sat, 11 Nov 2023 13:22:26 +0100 Subject: [PATCH] Generate truly random email addresses in factory Previously, it could happen under some (random) circumstances that a series of users got the same user name. This is caused by the usage of Forgery for generating a name. Forgery itself picks a random name from a list, and there is no check that two calls would indeed deliver two different names. In order to solve the issue, we generate a truly unique email address for specs, so that the problem won't arise again. --- spec/factories/shared_traits.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/shared_traits.rb b/spec/factories/shared_traits.rb index 52bcbd5f..3f6cbf63 100644 --- a/spec/factories/shared_traits.rb +++ b/spec/factories/shared_traits.rb @@ -8,7 +8,7 @@ FactoryBot.define do end trait :generated_email do - email { "#{name.underscore.tr(' ', '.')}@example.org" } + sequence(:email) {|n| "#{name.underscore.tr(' ', '.')}.#{n}@example.org" } end trait :generated_user_name do