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
|
||||
|
@ -5,7 +5,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-coffee:latest' }
|
||||
association :file_type, factory: :dot_coffee
|
||||
file_type { association :dot_coffee, user: user }
|
||||
help
|
||||
name { 'CoffeeScript' }
|
||||
network_enabled { false }
|
||||
@ -19,7 +19,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-html:latest' }
|
||||
association :file_type, factory: :dot_html
|
||||
file_type { association :dot_html, user: user }
|
||||
help
|
||||
name { 'HTML5' }
|
||||
network_enabled { false }
|
||||
@ -35,7 +35,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'openhpi/co_execenv_java:latest' }
|
||||
association :file_type, factory: :dot_java
|
||||
file_type { association :dot_java, user: user }
|
||||
help
|
||||
name { 'Java 8' }
|
||||
network_enabled { false }
|
||||
@ -51,7 +51,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-jruby:latest' }
|
||||
association :file_type, factory: :dot_rb
|
||||
file_type { association :dot_rb, user: user }
|
||||
help
|
||||
name { 'JRuby 1.7' }
|
||||
network_enabled { false }
|
||||
@ -67,7 +67,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-node:latest' }
|
||||
association :file_type, factory: :dot_js
|
||||
file_type { association :dot_js, user: user }
|
||||
help
|
||||
name { 'Node.js' }
|
||||
network_enabled { false }
|
||||
@ -81,7 +81,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'openhpi/co_execenv_python:latest' }
|
||||
association :file_type, factory: :dot_py
|
||||
file_type { association :dot_py, user: user }
|
||||
help
|
||||
name { 'Python 3.4' }
|
||||
network_enabled { false }
|
||||
@ -97,7 +97,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-ruby:latest' }
|
||||
association :file_type, factory: :dot_rb
|
||||
file_type { association :dot_rb, user: user }
|
||||
help
|
||||
name { 'Ruby 2.2' }
|
||||
network_enabled { false }
|
||||
@ -113,7 +113,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-sinatra:latest' }
|
||||
association :file_type, factory: :dot_rb
|
||||
file_type { association :dot_rb, user: user }
|
||||
exposed_ports { '4567' }
|
||||
help
|
||||
name { 'Sinatra' }
|
||||
@ -130,7 +130,7 @@ FactoryBot.define do
|
||||
created_by_teacher
|
||||
default_memory_limit
|
||||
docker_image { 'hklement/ubuntu-sqlite:latest' }
|
||||
association :file_type, factory: :dot_sql
|
||||
file_type { association :dot_sql, user: user }
|
||||
help
|
||||
name { 'SQLite' }
|
||||
network_enabled { false }
|
||||
|
@ -4,7 +4,10 @@ require 'seeds_helper'
|
||||
|
||||
def create_seed_file(exercise, path, file_attributes = {})
|
||||
file_extension = File.extname(path)
|
||||
file_type = FactoryBot.create(file_attributes[:file_type] || :"dot_#{file_extension.delete('.')}")
|
||||
file_type = FactoryBot.create(
|
||||
file_attributes[:file_type] || :"dot_#{file_extension.delete('.')}",
|
||||
user: exercise.user
|
||||
)
|
||||
name = File.basename(path).gsub(file_extension, '')
|
||||
file_attributes.merge!(file_type: file_type, name: name, path: path.split('/')[1..-2].join('/'), role: file_attributes[:role] || 'regular_file')
|
||||
if file_type.binary?
|
||||
|
@ -205,6 +205,10 @@ FactoryBot.define do
|
||||
end
|
||||
|
||||
trait :singleton_file_type do
|
||||
initialize_with { FileType.where(attributes).first_or_create }
|
||||
initialize_with do
|
||||
FileType.where(attributes.except(:user)).first_or_create do |file_type|
|
||||
file_type.user = user
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user