Move submission scoring from controller concern to submission model
Localization and markdown formatting is now done in a controller spec in order to bring this logic away from the data and towards the view.
This commit is contained in:

committed by
Sebastian Serth

parent
b847daf823
commit
b6bc578aea
54
spec/concerns/scoring_result_formatting_spec.rb
Normal file
54
spec/concerns/scoring_result_formatting_spec.rb
Normal file
@ -0,0 +1,54 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
class Controller < AnonymousController
|
||||
include ScoringResultFormatting
|
||||
end
|
||||
|
||||
describe ScoringResultFormatting do
|
||||
let(:controller) { Controller.new }
|
||||
let(:filename) { 'exercise.py' }
|
||||
let(:feedback_message) { '**good work**' }
|
||||
let(:outputs) { [{filename: filename, message: feedback_message}] }
|
||||
|
||||
describe 'feedback message' do
|
||||
let(:new_feedback_message) { controller.format_scoring_results(outputs).first[:message] }
|
||||
|
||||
context 'when the feedback message is not a path to a locale' do
|
||||
let(:feedback_message) { '**good work**' }
|
||||
|
||||
it 'renders the feedback message as markdown' do
|
||||
expect(new_feedback_message).to match('<p><strong>good work</strong></p>')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the feedback message is a valid path to a locale' do
|
||||
let(:feedback_message) { 'exercises.implement.default_test_feedback' }
|
||||
|
||||
it 'replaces the feedback message with the locale' do
|
||||
expect(new_feedback_message).to eq(I18n.t(feedback_message))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'filename' do
|
||||
let(:new_filename) { controller.format_scoring_results(outputs).first[:filename] }
|
||||
|
||||
context 'when the filename is not a path to a locale' do
|
||||
let(:filename) { 'exercise.py' }
|
||||
|
||||
it 'does not alter the filename' do
|
||||
expect(new_filename).to eq(filename)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the filename is a valid path to a locale' do
|
||||
let(:filename) { 'exercises.implement.not_graded' }
|
||||
|
||||
it 'replaces the filename with the locale' do
|
||||
expect(new_filename).to eq(I18n.t(filename))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,38 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SubmissionScoring do
|
||||
let(:submission) { FactoryBot.create(:submission, cause: 'submit') }
|
||||
|
||||
describe '#collect_test_results' do
|
||||
let(:runner) { FactoryBot.create :runner }
|
||||
|
||||
before do
|
||||
allow(Runner).to receive(:for).and_return(runner)
|
||||
allow(runner).to receive(:copy_files)
|
||||
allow(runner).to receive(:attach_to_execution).and_return(1.0)
|
||||
end
|
||||
|
||||
after { submission.calculate_score }
|
||||
|
||||
it 'executes every teacher-defined test file' do
|
||||
allow(submission).to receive(:score_submission)
|
||||
submission.collect_files.select(&:teacher_defined_assessment?).each do |file|
|
||||
allow(submission).to receive(:test_result).with(any_args, file).and_return({})
|
||||
end
|
||||
end
|
||||
|
||||
it 'scores the submission' do
|
||||
allow(submission).to receive(:score_submission).and_return([])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#score_submission', cleaning_strategy: :truncation do
|
||||
after { submission.score_submission([]) }
|
||||
|
||||
it 'assigns a score to the submissions' do
|
||||
expect(submission).to receive(:update).with(score: anything)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user