Prevent creation of temporary users while seeding
This commit is contained in:
@ -14,14 +14,14 @@ teacher = FactoryBot.create(:teacher, email: 'teacher@example.org')
|
||||
FactoryBot.create(:learner, email: 'learner@example.org')
|
||||
external_user = FactoryBot.create(:external_user)
|
||||
|
||||
# file types
|
||||
FileType.create_factories user: admin
|
||||
|
||||
# execution environments
|
||||
ExecutionEnvironment.create_factories user: admin
|
||||
|
||||
# exercises
|
||||
@exercises = find_factories_by_class(Exercise).map(&:name).index_with {|factory_name| FactoryBot.create(factory_name, user: teacher) }
|
||||
|
||||
# file types
|
||||
FileType.create_factories
|
||||
|
||||
# submissions
|
||||
FactoryBot.create(:submission, exercise: @exercises[:fibonacci], user: external_user)
|
||||
|
@ -13,24 +13,24 @@ passwords = ['password', 'password confirmation'].map do |attribute|
|
||||
end
|
||||
|
||||
if passwords.uniq.length == 1
|
||||
FactoryBot.create(:admin, email: email, name: 'Administrator', password: passwords.first)
|
||||
admin = FactoryBot.create(:admin, email: email, name: 'Administrator', password: passwords.first)
|
||||
else
|
||||
abort('Passwords do not match!')
|
||||
end
|
||||
|
||||
# file types
|
||||
FileType.create_factories user: admin
|
||||
|
||||
# execution environments
|
||||
ExecutionEnvironment.create_factories
|
||||
ExecutionEnvironment.create_factories user: admin
|
||||
|
||||
# exercises
|
||||
Exercise.create_factories
|
||||
Exercise.create_factories user: admin
|
||||
|
||||
# file types
|
||||
FileType.create_factories
|
||||
|
||||
# change all resources' author
|
||||
[ExecutionEnvironment, Exercise, FileType].each do |model|
|
||||
model.update(user_id: InternalUser.first.id)
|
||||
end
|
||||
|
||||
# delete temporary users
|
||||
InternalUser.where.not(id: InternalUser.first.id).delete_all
|
||||
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.
|
||||
CONFIRMATION_MESSAGE
|
||||
|
Reference in New Issue
Block a user