Skip to content

Commit 896a2c4

Browse files
committed
handle duplicated files on export
1 parent 13812ce commit 896a2c4

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

app/services/proforma_service/convert_task_to_proforma_task.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def initialize(task:, options: {})
66
super()
77
@task = task
88
@options = options
9+
@all_files = []
910
end
1011

1112
def execute
@@ -78,6 +79,21 @@ def tests
7879
end
7980
end
8081

82+
def task_files_equal?(task_file, other)
83+
task_file.filename == other.filename &&
84+
task_file.used_by_grader == other.used_by_grader &&
85+
task_file.visible == other.visible &&
86+
task_file.usage_by_lms == other.usage_by_lms &&
87+
task_file.internal_description == other.internal_description &&
88+
task_content_equal?(task_file, other)
89+
end
90+
91+
def task_content_equal?(task_file, other)
92+
task_file.content == other.content &&
93+
task_file.binary == other.binary &&
94+
task_file.mimetype == other.mimetype
95+
end
96+
8197
def task_file(file)
8298
task_file = ProformaXML::TaskFile.new(
8399
id: file.xml_id,
@@ -88,6 +104,11 @@ def task_file(file)
88104
internal_description: file.internal_description
89105
)
90106
add_content_to_task_file(file, task_file)
107+
108+
original_file = @all_files.find {|f| task_files_equal?(f, task_file) }
109+
return original_file if original_file
110+
111+
@all_files << task_file
91112
task_file
92113
end
93114

spec/services/proforma_service/convert_task_to_proforma_task_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,25 @@
273273
it 'creates a task with two tests' do
274274
expect(proforma_task.tests).to have(2).items
275275
end
276+
277+
context 'with different files' do
278+
let(:tests) do
279+
[build(:test, files: build_list(:task_file, 1, content: 'file1')),
280+
build(:test, files: build_list(:task_file, 1, content: 'file2'))]
281+
end
282+
283+
it 'creates a task with two files' do
284+
expect(proforma_task.all_files).to have(2).items
285+
end
286+
end
287+
288+
context 'with equal files used in both tests' do
289+
let(:tests) { build_list(:test, 2, files: build_list(:task_file, 1)) }
290+
291+
it 'creates a task with one file' do
292+
expect(proforma_task.all_files).to have(1).items
293+
end
294+
end
276295
end
277296

278297
context 'when exercise has description formatted in markdown' do

0 commit comments

Comments
 (0)