add default values to meta_data
fix specs
This commit is contained in:
@ -21,11 +21,11 @@ module ProformaService
|
|||||||
user: @user,
|
user: @user,
|
||||||
title: @task.title,
|
title: @task.title,
|
||||||
description: @task.description,
|
description: @task.description,
|
||||||
public: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:public)),
|
public: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:public)) || false,
|
||||||
hide_file_tree: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:hide_file_tree)),
|
hide_file_tree: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:hide_file_tree)) || false,
|
||||||
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)),
|
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)) || false,
|
||||||
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)),
|
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)) || false,
|
||||||
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty),
|
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty) || 1,
|
||||||
execution_environment_id: execution_environment_id,
|
execution_environment_id: execution_environment_id,
|
||||||
|
|
||||||
files: files
|
files: files
|
||||||
|
@ -49,26 +49,13 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
let(:model_solutions) { [] }
|
let(:model_solutions) { [] }
|
||||||
let(:exercise) { nil }
|
let(:exercise) { nil }
|
||||||
|
|
||||||
let(:meta_data) do
|
let(:meta_data) { {} }
|
||||||
{
|
|
||||||
CodeOcean: {
|
|
||||||
public: public,
|
|
||||||
hide_file_tree: hide_file_tree,
|
|
||||||
allow_file_creation: allow_file_creation,
|
|
||||||
allow_auto_completion: allow_auto_completion,
|
|
||||||
expected_difficulty: expected_difficulty,
|
|
||||||
execution_environment_id: execution_environment&.id,
|
|
||||||
files: files_meta_data,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
let(:public) { 'true' }
|
let(:public) { 'true' }
|
||||||
let(:hide_file_tree) { 'true' }
|
let(:hide_file_tree) { 'true' }
|
||||||
let(:allow_file_creation) { 'true' }
|
let(:allow_file_creation) { 'true' }
|
||||||
let(:allow_auto_completion) { 'true' }
|
let(:allow_auto_completion) { 'true' }
|
||||||
let(:expected_difficulty) { 7 }
|
let(:expected_difficulty) { 7 }
|
||||||
let!(:execution_environment) { create(:java) }
|
let!(:execution_environment) { create(:java) }
|
||||||
let(:files_meta_data) { {} }
|
|
||||||
|
|
||||||
it 'creates an exercise with the correct attributes' do
|
it 'creates an exercise with the correct attributes' do
|
||||||
expect(convert_to_exercise_service).to have_attributes(
|
expect(convert_to_exercise_service).to have_attributes(
|
||||||
@ -78,15 +65,51 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
unpublished: true,
|
unpublished: true,
|
||||||
user: user,
|
user: user,
|
||||||
files: be_empty,
|
files: be_empty,
|
||||||
public: true,
|
public: false,
|
||||||
hide_file_tree: true,
|
hide_file_tree: false,
|
||||||
allow_file_creation: true,
|
allow_file_creation: false,
|
||||||
allow_auto_completion: true,
|
allow_auto_completion: false,
|
||||||
expected_difficulty: 7,
|
expected_difficulty: 1,
|
||||||
execution_environment_id: execution_environment.id
|
execution_environment_id: nil
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it { is_expected.to be_valid }
|
||||||
|
|
||||||
|
context 'when meta_data is set' do
|
||||||
|
let(:meta_data) do
|
||||||
|
{
|
||||||
|
CodeOcean: {
|
||||||
|
public: public,
|
||||||
|
hide_file_tree: hide_file_tree,
|
||||||
|
allow_file_creation: allow_file_creation,
|
||||||
|
allow_auto_completion: allow_auto_completion,
|
||||||
|
expected_difficulty: expected_difficulty,
|
||||||
|
execution_environment_id: execution_environment&.id,
|
||||||
|
files: files_meta_data,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:files_meta_data) { {} }
|
||||||
|
|
||||||
|
it 'creates an exercise with the correct attributes' do
|
||||||
|
expect(convert_to_exercise_service).to have_attributes(
|
||||||
|
title: 'title',
|
||||||
|
description: 'description',
|
||||||
|
uuid: be_blank,
|
||||||
|
unpublished: true,
|
||||||
|
user: user,
|
||||||
|
files: be_empty,
|
||||||
|
public: true,
|
||||||
|
hide_file_tree: true,
|
||||||
|
allow_file_creation: true,
|
||||||
|
allow_auto_completion: true,
|
||||||
|
expected_difficulty: 7,
|
||||||
|
execution_environment_id: execution_environment.id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when execution environment is not set in meta_data' do
|
context 'when execution environment is not set in meta_data' do
|
||||||
let(:execution_environment) { nil }
|
let(:execution_environment) { nil }
|
||||||
|
|
||||||
@ -135,6 +158,13 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when file is a main_file' do
|
context 'when file is a main_file' do
|
||||||
|
let(:meta_data) do
|
||||||
|
{
|
||||||
|
CodeOcean: {
|
||||||
|
files: files_meta_data,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
let(:files_meta_data) { {"CO-#{file.id}".to_sym => {role: 'main_file'}} }
|
let(:files_meta_data) { {"CO-#{file.id}".to_sym => {role: 'main_file'}} }
|
||||||
|
|
||||||
it 'creates an exercise with a file that has the correct attributes' do
|
it 'creates an exercise with a file that has the correct attributes' do
|
||||||
@ -309,6 +339,13 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when test file is a teacher_defined_linter' do
|
context 'when test file is a teacher_defined_linter' do
|
||||||
|
let(:meta_data) do
|
||||||
|
{
|
||||||
|
CodeOcean: {
|
||||||
|
files: files_meta_data,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
let(:files_meta_data) { {"CO-#{test_file.id}".to_sym => {role: 'teacher_defined_linter'}} }
|
let(:files_meta_data) { {"CO-#{test_file.id}".to_sym => {role: 'teacher_defined_linter'}} }
|
||||||
|
|
||||||
it 'creates an exercise with a test' do
|
it 'creates an exercise with a test' do
|
||||||
@ -365,8 +402,8 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
convert_to_exercise_service.save
|
convert_to_exercise_service.save
|
||||||
expect(exercise.reload).to have_attributes(
|
expect(exercise.reload).to have_attributes(
|
||||||
id: exercise.id,
|
id: exercise.id,
|
||||||
title: task.title,
|
title: exercise.title,
|
||||||
description: task.description,
|
description: exercise.description,
|
||||||
execution_environment: exercise.execution_environment,
|
execution_environment: exercise.execution_environment,
|
||||||
uuid: exercise.uuid,
|
uuid: exercise.uuid,
|
||||||
user: exercise.user,
|
user: exercise.user,
|
||||||
|
@ -29,6 +29,10 @@ describe ProformaService::Import do
|
|||||||
instructions: 'instruction',
|
instructions: 'instruction',
|
||||||
execution_environment: execution_environment,
|
execution_environment: execution_environment,
|
||||||
files: files + tests,
|
files: files + tests,
|
||||||
|
hide_file_tree: true,
|
||||||
|
allow_file_creation: false,
|
||||||
|
allow_auto_completion: true,
|
||||||
|
expected_difficulty: 7,
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
user: user)
|
user: user)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user