Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'db/fixtures/development/35_emails.rb')
-rw-r--r--db/fixtures/development/35_emails.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/db/fixtures/development/35_emails.rb b/db/fixtures/development/35_emails.rb
new file mode 100644
index 00000000000..a743c326015
--- /dev/null
+++ b/db/fixtures/development/35_emails.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+class Gitlab::Seeder::Emails
+ attr_reader :user, :group_namespace_ids, :project_namespace_ids
+
+ def initialize(user, group_namespace_ids, project_namespace_ids)
+ @user = user
+ @group_namespace_ids = group_namespace_ids.sample(3)
+ @project_namespace_ids = project_namespace_ids.sample(3)
+ end
+
+ def seed!
+ company_email = "#{user.username}-work@example.com"
+ personal_email = "#{user.username}-home@example.com"
+ oss_email = "#{user.username}-oss@example.com"
+ unverified_email = "#{user.username}-unverified@example.com"
+
+ Email.create!(
+ user_id: user.id,
+ email: unverified_email
+ )
+
+ [company_email, personal_email, oss_email].each_with_index do |email, index|
+ email_id = Email.create!(
+ user_id: user.id,
+ email: email,
+ confirmed_at: DateTime.current
+ ).id
+ Users::NamespaceCommitEmail.create!(
+ user_id: user.id,
+ namespace_id: group_namespace_ids[index],
+ email_id: email_id
+ )
+ Users::NamespaceCommitEmail.create!(
+ user_id: user.id,
+ namespace_id: project_namespace_ids[index],
+ email_id: email_id
+ )
+ print '.'
+ end
+ end
+end
+
+Gitlab::Seeder.quiet do
+ puts "\nGenerating email data"
+
+ group_namespace_ids = Group.not_mass_generated.where('parent_id IS NULL').pluck(:id)
+ project_namespace_ids = Project.all.pluck(:project_namespace_id)
+
+ User.first(3).each do |user|
+ Gitlab::Seeder::Emails.new(user, group_namespace_ids, project_namespace_ids).seed!
+ rescue => e
+ warn "\nError seeding e-mails: #{e}"
+ end
+end