Skip to content

Commit 40543f9

Browse files
committed
add fallback for missing description
1 parent 648ce3f commit 40543f9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/services/proforma_service/convert_task_to_exercise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def import_task
2323
@exercise.assign_attributes(
2424
user: @user,
2525
title: @task.title,
26-
description: @task.description,
26+
description: @task.description.presence || @task.title,
2727
public: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'public')) || false,
2828
hide_file_tree: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'hide_file_tree')) || false,
2929
allow_file_creation: string_to_bool(extract_meta_data(@task.meta_data&.dig('meta-data'), 'allow_file_creation')) || false,

spec/services/proforma_service/convert_task_to_exercise_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
let(:task) do
3232
ProformaXML::Task.new(
3333
title: 'title',
34-
description: 'description',
34+
description:,
3535
proglang: {name: 'python', version: '3.4'},
3636
uuid: 'uuid',
3737
parent_uuid: 'parent_uuid',
@@ -49,6 +49,7 @@
4949
let(:model_solutions) { [] }
5050
let(:exercise) { nil }
5151

52+
let(:description) { 'description' }
5253
let(:meta_data) { {} }
5354
let(:public) { 'true' }
5455
let(:hide_file_tree) { 'true' }
@@ -76,6 +77,16 @@
7677

7778
it { is_expected.to be_valid }
7879

80+
context 'when task has no description' do
81+
let(:description) { nil }
82+
83+
it 'creates an exercise with the correct description fallback' do
84+
expect(convert_to_exercise_service).to have_attributes(
85+
description: 'title'
86+
)
87+
end
88+
end
89+
7990
context 'when meta_data is set' do
8091
let(:meta_data) do
8192
{

0 commit comments

Comments
 (0)