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.
This commit is contained in:
Sebastian Serth
2023-11-11 13:22:26 +01:00
parent 738f082f37
commit bcbb2d2eb6

View File

@ -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