Skip to content

Commit

Permalink
Handle incorrect setup of the question formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
LaRita Robinson committed Feb 26, 2025
1 parent d413bee commit 5c8906d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/services/question_formatter/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def format_sub_question(sub_question)

def format_by_type
method = @question.class.model_exporter
send(method)
begin
send(method)
rescue => e
"Question type: #{question_type} requires a valid export format method"
end
end

private
Expand Down
13 changes: 13 additions & 0 deletions spec/services/question_formatter/base_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@
it 'has the correct public methods' do
expect(subject).to respond_to(:format_content)
end

context 'when calling #format_content' do
describe 'when question model has no valid model_exporter method defined' do
before do
allow(question.class).to receive(:model_exporter).and_return('abc')
allow(subject).to receive(:divider_line).and_return("\n---\n\n")
end

it 'handles errors gracefully' do
expect(subject.format_content).to eq("Question type: Essay requires a valid export format method\n---\n\n")
end
end
end
end

0 comments on commit 5c8906d

Please sign in to comment.