fix and add specs

This commit is contained in:
Karol
2022-08-31 20:51:58 +02:00
parent 76c9dfa4e5
commit 5ace779d0c
8 changed files with 104 additions and 47 deletions

View File

@ -37,6 +37,7 @@ module ProformaService
allow_auto_completion: @exercise.allow_auto_completion,
expected_difficulty: @exercise.expected_difficulty,
execution_environment_id: @exercise.execution_environment_id,
files: task_files_meta_data,
},
},
}.compact
@ -92,17 +93,26 @@ module ProformaService
[
task_file(file).tap do |t_file|
t_file.used_by_grader = true
t_file.internal_description = 'teacher_defined_test'
end,
]
end
def task_files
@exercise.files
.filter do |file|
def exercise_files
@exercise.files.filter do |file|
!file.role.in? %w[reference_implementation teacher_defined_test
teacher_defined_linter]
end.map do |file|
end
end
def task_files_meta_data
exercise_files.to_h do |file|
# added CO- to id, otherwise the key would have CodeOcean as a prefix after export and import (cause unknown)
["CO-#{file.id}", {role: file.role}]
end
end
def task_files
exercise_files.map do |file|
task_file(file)
end
end
@ -112,8 +122,7 @@ module ProformaService
id: file.id,
filename: filename(file),
usage_by_lms: file.read_only ? 'display' : 'edit',
visible: file.hidden ? 'no' : 'yes',
# internal_description: file.role || 'regular_file'
visible: file.hidden ? 'no' : 'yes'
)
add_content_to_task_file(file, task_file)
task_file
@ -121,8 +130,7 @@ module ProformaService
def filename(file)
if file.path.present? && file.path != '.'
::File.join(file.path,
file.name_with_extension)
::File.join(file.path, file.name_with_extension)
else
file.name_with_extension
end

View File

@ -21,10 +21,10 @@ module ProformaService
user: @user,
title: @task.title,
description: @task.description,
public: @task.meta_data[:CodeOcean]&.dig(:public) == 'true',
hide_file_tree: @task.meta_data[:CodeOcean]&.dig(:hide_file_tree) == 'true',
allow_file_creation: @task.meta_data[:CodeOcean]&.dig(:allow_file_creation) == 'true',
allow_auto_completion: @task.meta_data[:CodeOcean]&.dig(:allow_auto_completion) == 'true',
public: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:public)),
hide_file_tree: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:hide_file_tree)),
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)),
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)),
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty),
execution_environment_id: @task.meta_data[:CodeOcean]&.dig(:execution_environment_id),
@ -32,6 +32,13 @@ module ProformaService
)
end
def string_to_bool(str)
return true if str == 'true'
return false if str == 'false'
nil
end
def files
model_solution_files + test_files + task_files.values
end
@ -68,7 +75,7 @@ module ProformaService
hidden: file.visible == 'no',
name: File.basename(file.filename, '.*'),
read_only: file.usage_by_lms != 'edit',
role: 'regular_file',
role: @task.meta_data[:CodeOcean]&.dig(:files)&.dig("CO-#{file.id}".to_sym)&.dig(:role) || 'regular_file',
path: File.dirname(file.filename).in?(['.', '']) ? nil : File.dirname(file.filename)
)
if file.binary