From 6ad5274e67c9c971a28a183738b05829cdb4ee59 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 22 Sep 2022 13:33:45 +0200 Subject: [PATCH] Fix seeds for execution environment import and study group membership --- db/seeds/development.rb | 24 ++++++++++++++++++++---- db/seeds/production.rb | 23 +++++++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/db/seeds/development.rb b/db/seeds/development.rb index db581f28..0b69a724 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'highline/import' + # consumers FactoryBot.create(:consumer) FactoryBot.create(:consumer, name: 'openSAP') @@ -9,15 +11,17 @@ FactoryBot.create(:consumer, name: 'Xikolo Development', oauth_key: 'consumer', # users # Set default_url_options explicitly, required for rake task Rails.application.routes.default_url_options = Rails.application.config.action_mailer.default_url_options -admin = FactoryBot.create(:admin) -teacher = FactoryBot.create(:teacher, email: 'teacher@example.org') -FactoryBot.create(:learner, email: 'learner@example.org') -external_user = FactoryBot.create(:external_user) +UserMailer.delivery_method = :test +admin = FactoryBot.create(:admin, study_groups: StudyGroup.all) +teacher = FactoryBot.create(:teacher, email: 'teacher@example.org', study_groups: StudyGroup.all) +FactoryBot.create(:learner, email: 'learner@example.org', study_groups: StudyGroup.all) +external_user = FactoryBot.create(:external_user, study_groups: StudyGroup.all) # file types FileType.create_factories user: admin # execution environments +ExecutionEnvironment.skip_callback(:commit, :after, :sync_runner_environment) ExecutionEnvironment.create_factories user: admin # exercises @@ -25,3 +29,15 @@ ExecutionEnvironment.create_factories user: admin # submissions FactoryBot.create(:submission, exercise: @exercises[:fibonacci], user: external_user) + +say(<<~CONFIRMATION_MESSAGE) + Development data has been seeded successfully. + + As part of this setup, some execution environments have been \ + stored in the database. However, these haven't been yet \ + synchronized with a runner management. Please take care \ + to configure a runner management according to the \ + documentation and synchronize environments thorugh the \ + user interface. To do so, open `/execution_environments` \ + and click on the "Synchronize all" button. +CONFIRMATION_MESSAGE diff --git a/db/seeds/production.rb b/db/seeds/production.rb index 12a7c507..4f279da6 100644 --- a/db/seeds/production.rb +++ b/db/seeds/production.rb @@ -13,7 +13,7 @@ passwords = ['password', 'password confirmation'].map do |attribute| end if passwords.uniq.length == 1 - admin = FactoryBot.create(:admin, email: email, name: 'Administrator', password: passwords.first) + admin = FactoryBot.create(:admin, email: email, name: 'Administrator', password: passwords.first, study_groups: StudyGroup.all) else abort('Passwords do not match!') end @@ -22,15 +22,26 @@ end FileType.create_factories user: admin # execution environments +ExecutionEnvironment.skip_callback(:commit, :after, :sync_runner_environment) ExecutionEnvironment.create_factories user: admin # exercises Exercise.create_factories user: admin say(<<~CONFIRMATION_MESSAGE) - Production data has been seeded successfully. As part \ - of this setup, a test email was sent to '#{email}'. You \ - can safely ignore this mail as your account is already \ - confirmed. However, if you haven't received any email, \ - you should check the server's mail settings. + Production data has been seeded successfully. + + As part of this setup, a test email was sent to \ + '#{email}'. You can safely ignore this mail as your \ + account is already confirmed. However, if you \ + haven't received any email, you should check the \ + server's mail settings. + + Additionally, some execution environments have been \ + stored in the database. However, these haven't been yet \ + synchronized with a runner management. Please take care \ + to configure a runner management according to the \ + documentation and synchronize environments thorugh the \ + user interface. To do so, open `/execution_environments` \ + and click on the "Synchronize all" button. CONFIRMATION_MESSAGE