From 06053d437df486fa1637dd7e0397f024473a7034 Mon Sep 17 00:00:00 2001 From: Karol Date: Tue, 10 Dec 2019 16:37:36 +0100 Subject: [PATCH] add specs for nil paths --- .../convert_task_to_exercise_spec.rb | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/services/proforma_service/convert_task_to_exercise_spec.rb b/spec/services/proforma_service/convert_task_to_exercise_spec.rb index 4f0a3b8c..1d66d32f 100644 --- a/spec/services/proforma_service/convert_task_to_exercise_spec.rb +++ b/spec/services/proforma_service/convert_task_to_exercise_spec.rb @@ -69,7 +69,7 @@ describe ProformaService::ConvertTaskToExercise do Proforma::TaskFile.new( id: 'id', content: content, - filename: 'filename.txt', + filename: "#{path}filename.txt", used_by_grader: 'used_by_grader', visible: 'yes', usage_by_lms: usage_by_lms, @@ -82,6 +82,7 @@ describe ProformaService::ConvertTaskToExercise do let(:mimetype) { 'mimetype' } let(:binary) { false } let(:content) { 'content' } + let(:path) {} it 'creates an exercise with a file that has the correct attributes' do expect(convert_to_exercise_service.files.first).to have_attributes( @@ -90,7 +91,8 @@ describe ProformaService::ConvertTaskToExercise do role: 'regular_file', hidden: false, read_only: true, - file_type: be_a(FileType).and(have_attributes(file_extension: '.txt')) + file_type: be_a(FileType).and(have_attributes(file_extension: '.txt')), + path: nil ) end @@ -98,6 +100,22 @@ describe ProformaService::ConvertTaskToExercise do expect { convert_to_exercise_service.save! }.to change(Exercise, :count).by(1) end + context 'when path is folder/' do + let(:path) { 'folder/' } + + it 'creates an exercise with a file that has the correct path' do + expect(convert_to_exercise_service.files.first).to have_attributes(path: 'folder') + end + end + + context 'when path is ./' do + let(:path) { './' } + + it 'creates an exercise with a file that has the correct path' do + expect(convert_to_exercise_service.files.first).to have_attributes(path: nil) + end + end + context 'when file is very large' do let(:content) { 'test' * 10**5 }