diff --git a/app/services/proforma_service/convert_task_to_exercise.rb b/app/services/proforma_service/convert_task_to_exercise.rb index 222a56b8..f9682bf3 100644 --- a/app/services/proforma_service/convert_task_to_exercise.rb +++ b/app/services/proforma_service/convert_task_to_exercise.rb @@ -101,7 +101,7 @@ module ProformaService end def file_type(extension) - FileType.find_or_create_by(file_extension: extension) do |file_type| + FileType.find_or_create_by(file_extension: extension.presence) do |file_type| file_type.name = extension[1..] file_type.user = @user file_type.indent_size = 4 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 b5b685d7..38439c95 100644 --- a/spec/services/proforma_service/convert_task_to_exercise_spec.rb +++ b/spec/services/proforma_service/convert_task_to_exercise_spec.rb @@ -232,6 +232,20 @@ describe ProformaService::ConvertTaskToExercise do expect { convert_to_exercise_service.save! }.to change(FileType, :count).by(1) end end + + context 'when file has a Makefile' do + let!(:file_type) { create(:makefile) } + + let(:filename) { 'Makefile' } + + it 'creates a new Exercise on save' do + expect { convert_to_exercise_service.save! }.to change(Exercise, :count).by(1) + end + + it 'creates an exercise with a file with correct attributes' do + expect(convert_to_exercise_service.files.first.file_type).to eql file_type + end + end end context 'when task has a model-solution' do