Send score for all members of a programming group

This commit is contained in:
kiragrammel
2023-08-10 17:11:15 +02:00
committed by Sebastian Serth
parent 2fb8def1d0
commit e2baa2ee55
12 changed files with 77 additions and 47 deletions

View File

@ -102,7 +102,7 @@ describe Lti do
end
end
describe '#send_score' do
describe '#send_scores' do
let(:consumer) { create(:consumer) }
let(:score) { 0.5 }
let(:submission) { create(:submission) }
@ -114,7 +114,7 @@ describe Lti do
context 'with an invalid score' do
it 'raises an exception' do
allow(submission).to receive(:normalized_score).and_return Lti::MAXIMUM_SCORE * 2
expect { controller.send(:send_score, submission) }.to raise_error(Lti::Error)
expect { controller.send(:send_scores, submission) }.to raise_error(Lti::Error)
end
end
@ -124,13 +124,13 @@ describe Lti do
it 'returns a corresponding status' do
allow_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(false)
allow(submission).to receive(:normalized_score).and_return score
expect(controller.send(:send_score, submission)[:status]).to eq('unsupported')
expect(controller.send(:send_scores, submission).first[:status]).to eq('unsupported')
end
end
context 'when grading is supported' do
let(:response) { double }
let(:send_score) { controller.send(:send_score, submission) }
let(:send_scores) { controller.send(:send_scores, submission).first }
before do
allow_any_instance_of(IMS::LTI::ToolProvider).to receive(:outcome_service?).and_return(true)
@ -144,13 +144,13 @@ describe Lti do
it 'sends the score' do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:post_replace_result!).with(score)
send_score
send_scores
end
it 'returns code, message, and status' do
expect(send_score[:code]).to eq(response.response_code)
expect(send_score[:message]).to eq(response.body)
expect(send_score[:status]).to eq(response.code_major)
expect(send_scores[:code]).to eq(response.response_code)
expect(send_scores[:message]).to eq(response.body)
expect(send_scores[:status]).to eq(response.code_major)
end
end
end
@ -160,7 +160,7 @@ describe Lti do
submission.contributor.consumer = nil
allow(submission).to receive(:normalized_score).and_return score
expect(controller.send(:send_score, submission)[:status]).to eq('error')
expect(controller.send(:send_scores, submission).first[:status]).to eq('error')
end
end
end

View File

@ -325,7 +325,7 @@ describe ExercisesController do
context 'when the score transmission succeeds' do
before do
allow(controller).to receive(:send_score).and_return(status: 'success')
allow(controller).to receive(:send_scores).and_return([{status: 'success'}])
perform_request
end
@ -341,7 +341,7 @@ describe ExercisesController do
context 'when the score transmission fails' do
before do
allow(controller).to receive(:send_score).and_return(status: 'unsupported')
allow(controller).to receive(:send_scores).and_return([{status: 'unsupported'}])
perform_request
end
@ -351,8 +351,11 @@ describe ExercisesController do
expect(assigns(:submission)).to be_a(Submission)
end
it 'returns an error message' do
expect(response.parsed_body).to eq('danger' => I18n.t('exercises.submit.failure'))
end
expect_json
expect_http_status(:service_unavailable)
end
end
@ -369,7 +372,7 @@ describe ExercisesController do
end
it 'does not send scores' do
expect(controller).not_to receive(:send_score)
expect(controller).not_to receive(:send_scores)
end
expect_json

View File

@ -91,7 +91,7 @@ describe Exercise do
context 'without submissions' do
it 'returns nil' do
expect(exercise.average_score).to be 0
expect(exercise.average_score).to be 0.0
end
end