Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/services/proforma_service/convert_task_to_proforma_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def initialize(task:, options: {})
super()
@task = task
@options = options
@all_files = []
end

def execute
Expand Down Expand Up @@ -78,6 +79,21 @@ def tests
end
end

def task_files_equal?(task_file, other)
task_file.filename == other.filename &&
task_file.used_by_grader == other.used_by_grader &&
task_file.visible == other.visible &&
task_file.usage_by_lms == other.usage_by_lms &&
task_file.internal_description == other.internal_description &&
task_content_equal?(task_file, other)
end

def task_content_equal?(task_file, other)
task_file.content == other.content &&
task_file.binary == other.binary &&
task_file.mimetype == other.mimetype
end

def task_file(file)
task_file = ProformaXML::TaskFile.new(
id: file.xml_id,
Expand All @@ -88,6 +104,11 @@ def task_file(file)
internal_description: file.internal_description
)
add_content_to_task_file(file, task_file)

original_file = @all_files.find {|f| task_files_equal?(f, task_file) }
return original_file if original_file

@all_files << task_file
task_file
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@
it 'creates a task with two tests' do
expect(proforma_task.tests).to have(2).items
end

context 'with different files' do
let(:tests) do
[build(:test, files: build_list(:task_file, 1, content: 'file1')),
build(:test, files: build_list(:task_file, 1, content: 'file2'))]
end

it 'creates a task with two files' do
expect(proforma_task.all_files).to have(2).items
end
end

context 'with equal files used in both tests' do
let(:tests) { build_list(:test, 2, files: build_list(:task_file, 1)) }

it 'creates a task with one file' do
expect(proforma_task.all_files).to have(1).items
end
end
end

context 'when exercise has description formatted in markdown' do
Expand Down
Loading