Skip to content

Commit ad90382

Browse files
kkoehnMrSerth
andcommitted
Update app/services/proforma_service/convert_exercise_to_task.rb
Co-authored-by: Sebastian Serth <[email protected]>
1 parent e2d477a commit ad90382

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

app/services/proforma_service/convert_exercise_to_task.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def uuid
7777
end
7878

7979
def model_solutions
80-
model_solutions_files = @exercise.files.filter {|file| file.role == 'reference_implementation' }.group_by {|file| xml_id_from_file(file).first }
81-
model_solutions_files.map do |xml_id, files|
80+
@exercise.files.filter(&:reference_implementation?).group_by {|file| xml_id_from_file(file).first }.map do |xml_id, files|
8281
ProformaXML::ModelSolution.new(
8382
id: xml_id,
8483
files: files.map {|file| model_solution_file(file) }

app/services/proforma_service/convert_task_to_exercise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def task_files
107107
def codeocean_file_from_task_file(file, parent_object = nil)
108108
extension = File.extname(file.filename)
109109
# checking the last element of xml_id_path array for file.id
110-
codeocean_file = @exercise.files.where('array_length(xml_id_path, 1) IS NOT NULL AND xml_id_path[array_length(xml_id_path, 1)] = ?', file.id).first_or_initialize
110+
codeocean_file = @exercise.files.detect {|f| f.xml_id_path.last == file.id } || @exercise.files.new
111111
codeocean_file.assign_attributes(
112112
context: @exercise,
113113
file_type: file_type(extension),

spec/services/proforma_service/convert_exercise_to_task_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
end
127127

128128
context 'when xml_id_path is set for file' do
129-
let(:file) { create(:file, xml_id_path: ['foobar']) }
129+
let(:file) { create(:file, xml_id_path: ['foobar'], context: create(:dummy)) }
130130

131131
it 'does not change xml_id_path' do
132132
expect { convert_to_task.execute }.not_to change(file.reload, :xml_id_path)

spec/services/proforma_service/convert_task_to_exercise_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@
564564
description: 'exercise-description')
565565
end
566566
let(:co_files) do
567-
[create(:file, xml_id_path: ['id'], role: 'regular_file'),
568-
create(:file, xml_id_path: %w[ms-id ms-file-id], role: 'reference_implementation'),
569-
create(:test_file, xml_id_path: %w[test-id test-file-id])]
567+
[build(:file, xml_id_path: ['id'], role: 'regular_file'),
568+
build(:file, xml_id_path: %w[ms-id ms-file-id], role: 'reference_implementation'),
569+
build(:test_file, xml_id_path: %w[test-id test-file-id])]
570570
end
571571

572572
it 'reuses existing file' do

0 commit comments

Comments
 (0)