From 1e5a9b0825de881d5f998328f08b3c65539169b8 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Wed, 7 Apr 2021 17:45:38 +0200 Subject: [PATCH] Remove unused SubmissionsController#stop action --- app/assets/javascripts/editor/submissions.js | 3 +- app/controllers/submissions_controller.rb | 10 ----- app/views/submissions/show.json.jbuilder | 1 - config/routes.rb | 1 - .../submissions_controller_spec.rb | 41 ++----------------- 5 files changed, 5 insertions(+), 51 deletions(-) diff --git a/app/assets/javascripts/editor/submissions.js b/app/assets/javascripts/editor/submissions.js index 4b810cce..05064bc0 100644 --- a/app/assets/javascripts/editor/submissions.js +++ b/app/assets/javascripts/editor/submissions.js @@ -163,12 +163,11 @@ CodeOceanEditorSubmissions = { runSubmission: function (submission) { //Run part starts here - $('#stop').data('url', submission.stop_url); this.running = true; this.showSpinner($('#run')); $('#score_div').addClass('d-none'); this.toggleButtonStates(); - var url = submission.run_url.replace(this.FILENAME_URL_PLACEHOLDER, CodeOceanEditor.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor + const url = submission.run_url.replace(this.FILENAME_URL_PLACEHOLDER, CodeOceanEditor.active_file.filename.replace(/#$/,'')); // remove # if it is the last character, this is not part of the filename and just an anchor this.initializeSocketForRunning(url); }, diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 1f3ce6cb..c045432b 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -412,16 +412,6 @@ class SubmissionsController < ApplicationController def statistics end - def stop - Rails.logger.debug('stopping submission ' + @submission.id.to_s) - container = Docker::Container.get(params[:container_id]) - DockerClient.destroy_container(container) - rescue Docker::Error::NotFoundError => error - Sentry.capture_exception(error) - ensure - head :ok - end - def test hijack do |tubesock| unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive? diff --git a/app/views/submissions/show.json.jbuilder b/app/views/submissions/show.json.jbuilder index b66919dc..8ad8960a 100644 --- a/app/views/submissions/show.json.jbuilder +++ b/app/views/submissions/show.json.jbuilder @@ -1,7 +1,6 @@ json.extract! @submission, :id, :files json.download_url download_submission_path(@submission, format: :json) json.score_url score_submission_path(@submission, format: :json) -json.stop_url stop_submission_path(@submission, format: :json) json.download_file_url download_file_submission_path(@submission, 'a.', format: :json).gsub(/a\.\.json$/, '{filename}.json') json.render_url render_submission_path(@submission, 'a.', format: :json).gsub(/a\.\.json$/, '{filename}.json') json.run_url run_submission_path(@submission, 'a.', format: :json).gsub(/a\.\.json$/, '{filename}.json') diff --git a/config/routes.rb b/config/routes.rb index 891ee4cb..5e512d56 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -148,7 +148,6 @@ Rails.application.routes.draw do get 'run/:filename', as: :run, constraints: {filename: FILENAME_REGEXP}, action: :run get :score get :statistics - post :stop get 'test/:filename', as: :test, constraints: {filename: FILENAME_REGEXP}, action: :test end end diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb index 3cfecc64..7512a414 100644 --- a/spec/controllers/submissions_controller_spec.rb +++ b/spec/controllers/submissions_controller_spec.rb @@ -191,13 +191,11 @@ describe SubmissionsController do end end - [:score, :stop].each do |action| - describe "##{action}_url" do - let(:url) { JSON.parse(response.body).with_indifferent_access.fetch("#{action}_url") } + describe "#score_url" do + let(:url) { JSON.parse(response.body).with_indifferent_access.fetch("score_url") } - it "corresponds to the #{action} path" do - expect(url).to eq(Rails.application.routes.url_helpers.send(:"#{action}_submission_path", submission, format: :json)) - end + it "corresponds to the score path" do + expect(url).to eq(Rails.application.routes.url_helpers.score_submission_path(submission, format: :json)) end end end @@ -209,37 +207,6 @@ describe SubmissionsController do pending("todo: mock puma webserver or encapsulate tubesock call (Tubesock::HijackNotAvailable)") end - describe 'POST #stop' do - let(:perform_request) { proc { post :stop, params: { container_id: CONTAINER.id, id: submission.id } } } - - context 'when the container can be found' do - before(:each) do - expect(Docker::Container).to receive(:get).and_return(CONTAINER) - #expect(Rails.logger).to receive(:debug).at_least(:once).and_call_original - perform_request.call - end - - it 'renders nothing' do - expect(response.body).to be_blank - end - - expect_status(200) - end - - context 'when the container cannot be found' do - before(:each) do - expect(Docker::Container).to receive(:get).and_raise(Docker::Error::NotFoundError) - perform_request.call - end - - it 'renders nothing' do - expect(response.body).to be_blank - end - - expect_status(200) - end - end - describe 'GET #test' do let(:filename) { submission.collect_files.detect(&:teacher_defined_assessment?).name_with_extension } let(:output) { {} }