Fix rubocop, I18n, cleanup rebase
This commit is contained in:

committed by
Sebastian Serth

parent
2dff81a510
commit
5cc180d0e9
2
Gemfile
2
Gemfile
@ -16,8 +16,8 @@ gem 'highline'
|
||||
gem 'i18n-js'
|
||||
gem 'ims-lti', '< 2.0.0'
|
||||
gem 'jbuilder'
|
||||
gem 'js-routes'
|
||||
gem 'json_schemer'
|
||||
gem 'js-routes'
|
||||
gem 'kramdown'
|
||||
gem 'mimemagic'
|
||||
gem 'nokogiri'
|
||||
|
@ -1,11 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ScoringResultFormatting
|
||||
def format_scoring_results(outputs)
|
||||
outputs.map do |output|
|
||||
output[:message] = t(output[:message], default: render_markdown(output[:message]))
|
||||
output[:filename] = t(output[:filename], default: output[:filename])
|
||||
output
|
||||
end
|
||||
end
|
||||
end
|
@ -3,7 +3,6 @@
|
||||
class RemoteEvaluationController < ApplicationController
|
||||
include RemoteEvaluationParameters
|
||||
include Lti
|
||||
include ScoringResultFormatting
|
||||
|
||||
skip_after_action :verify_authorized
|
||||
skip_before_action :verify_authenticity_token
|
||||
@ -63,7 +62,7 @@ status: 202}
|
||||
validation_token = remote_evaluation_params[:validation_token]
|
||||
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(validation_token: validation_token))
|
||||
@submission = Submission.create(build_submission_params(cause, remote_evaluation_mapping))
|
||||
format_scoring_results(@submission.calculate_score)
|
||||
@submission.calculate_score
|
||||
else
|
||||
# TODO: better output
|
||||
# TODO: check token expired?
|
||||
|
@ -119,7 +119,7 @@ class RequestForCommentsController < ApplicationController
|
||||
if @request_for_comment.save
|
||||
# create thread here and execute tests. A run is triggered from the frontend and does not need to be handled here.
|
||||
Thread.new do
|
||||
@request_for_comment.submission.calculate_score
|
||||
switch_locale { @request_for_comment.submission.calculate_score }
|
||||
ensure
|
||||
ActiveRecord::Base.connection_pool.release_connection
|
||||
end
|
||||
|
@ -5,7 +5,6 @@ class SubmissionsController < ApplicationController
|
||||
include CommonBehavior
|
||||
include Lti
|
||||
include SubmissionParameters
|
||||
include ScoringResultFormatting
|
||||
include Tubesock::Hijack
|
||||
|
||||
before_action :set_submission,
|
||||
@ -35,15 +34,6 @@ class SubmissionsController < ApplicationController
|
||||
create_and_respond(object: @submission)
|
||||
end
|
||||
|
||||
def command_substitutions(filename)
|
||||
{
|
||||
class_name: File.basename(filename, File.extname(filename)).upcase_first,
|
||||
filename: filename,
|
||||
module_name: File.basename(filename, File.extname(filename)).underscore,
|
||||
}
|
||||
end
|
||||
private :command_substitutions
|
||||
|
||||
def copy_comments
|
||||
# copy each annotation and set the target_file.id
|
||||
params[:annotations_arr]&.each do |annotation|
|
||||
@ -247,7 +237,7 @@ class SubmissionsController < ApplicationController
|
||||
hijack do |tubesock|
|
||||
return kill_socket(tubesock) if @embed_options[:disable_run]
|
||||
|
||||
tubesock.send_data(JSON.dump(format_scoring_results(@submission.calculate_score)))
|
||||
tubesock.send_data(JSON.dump(@submission.calculate_score))
|
||||
# To enable hints when scoring a submission, uncomment the next line:
|
||||
# send_hints(tubesock, StructuredError.where(submission: @submission))
|
||||
rescue Runner::Error => e
|
||||
|
@ -163,10 +163,10 @@ class Submission < ApplicationRecord
|
||||
end
|
||||
output.merge!(container_execution_time: execution_time, status: exit_code.zero? ? :ok : :failed)
|
||||
rescue Runner::Error::ExecutionTimeout => e
|
||||
Rails.logger.debug("Running tests in #{file.name_with_extension} for submission #{id} timed out: #{e.message}")
|
||||
Rails.logger.debug { "Running tests in #{file.name_with_extension} for submission #{id} timed out: #{e.message}" }
|
||||
output.merge!(status: :timeout, container_execution_time: e.execution_duration)
|
||||
rescue Runner::Error => e
|
||||
Rails.logger.debug("Running tests in #{file.name_with_extension} for submission #{id} failed: #{e.message}")
|
||||
Rails.logger.debug { "Running tests in #{file.name_with_extension} for submission #{id} failed: #{e.message}" }
|
||||
output.merge!(status: :failed, container_execution_time: e.execution_duration)
|
||||
ensure
|
||||
output.merge!(stdout: stdout, stderr: stderr)
|
||||
@ -212,7 +212,7 @@ class Submission < ApplicationRecord
|
||||
|
||||
def command_substitutions(filename)
|
||||
{
|
||||
class_name: File.basename(filename, File.extname(filename)).camelize,
|
||||
class_name: File.basename(filename, File.extname(filename)).upcase_first,
|
||||
filename: filename,
|
||||
module_name: File.basename(filename, File.extname(filename)).underscore,
|
||||
}
|
||||
@ -245,10 +245,10 @@ class Submission < ApplicationRecord
|
||||
|
||||
if file.teacher_defined_linter?
|
||||
LinterCheckRun.create_from(testrun, assessment)
|
||||
assessment = assessor.translate_linter(assessment, session[:locale])
|
||||
assessment = assessor.translate_linter(assessment, I18n.locale)
|
||||
|
||||
# replace file name with hint if linter is not used for grading. Refactor!
|
||||
filename = 'exercises.implement.not_graded' if file.weight.zero?
|
||||
filename = I18n.t('exercises.implement.not_graded') if file.weight.zero?
|
||||
end
|
||||
|
||||
output.merge!(assessment)
|
||||
@ -257,11 +257,16 @@ class Submission < ApplicationRecord
|
||||
|
||||
def feedback_message(file, output)
|
||||
if output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_test'
|
||||
'exercises.implement.default_test_feedback'
|
||||
I18n.t('exercises.implement.default_test_feedback')
|
||||
elsif output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_linter'
|
||||
'exercises.implement.default_linter_feedback'
|
||||
I18n.t('exercises.implement.default_linter_feedback')
|
||||
else
|
||||
file.feedback_message
|
||||
# The render_markdown method from application_helper.rb is not available in model classes.
|
||||
ActionController::Base.helpers.sanitize(
|
||||
Kramdown::Document.new(file.feedback_message).to_html,
|
||||
tags: %w[strong],
|
||||
attributes: []
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Runner::Connection
|
||||
|
||||
def send(raw_data)
|
||||
encoded_message = encode(raw_data)
|
||||
Rails.logger.debug("#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}")
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}" }
|
||||
@socket.send(encoded_message)
|
||||
end
|
||||
|
||||
@ -52,7 +52,7 @@ class Runner::Connection
|
||||
end
|
||||
|
||||
def on_message(raw_event)
|
||||
Rails.logger.debug("#{Time.zone.now.getutc}: Receiving from #{@socket.url}: #{raw_event.data.inspect}")
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc}: Receiving from #{@socket.url}: #{raw_event.data.inspect}" }
|
||||
event = decode(raw_event)
|
||||
return unless BACKEND_OUTPUT_SCHEMA.valid?(event)
|
||||
|
||||
@ -72,7 +72,7 @@ class Runner::Connection
|
||||
def on_error(_event); end
|
||||
|
||||
def on_close(_event)
|
||||
Rails.logger.debug("#{Time.zone.now.getutc}: Closing connection to #{@socket.url} with status: #{@status}")
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc}: Closing connection to #{@socket.url} with status: #{@status}" }
|
||||
case @status
|
||||
when :timeout
|
||||
raise Runner::Error::ExecutionTimeout.new('Execution exceeded its time limit')
|
||||
|
@ -1,54 +0,0 @@
|
||||
# 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
|
Reference in New Issue
Block a user