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

@ -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