merge master

This commit is contained in:
Karol
2022-08-20 22:20:52 +02:00
291 changed files with 5413 additions and 9429 deletions

View File

@ -9,7 +9,7 @@ describe Admin::DashboardController do
describe 'with format HTML' do
before { get :show }
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
@ -17,7 +17,7 @@ describe Admin::DashboardController do
before { get :show, format: :json }
expect_json
expect_status(200)
expect_http_status(:ok)
end
end
end

View File

@ -43,14 +43,14 @@ describe ApplicationController do
context "when using the 'custom_locale' parameter" do
it 'overwrites the session' do
expect(session).to receive(:[]=).with(:locale, locale.to_s)
expect(session).to receive(:[]=).with(:locale, locale)
get :welcome, params: {custom_locale: locale}
end
end
context "when using the 'locale' parameter" do
it 'overwrites the session' do
expect(session).to receive(:[]=).with(:locale, locale.to_s)
expect(session).to receive(:[]=).with(:locale, locale)
get :welcome, params: {locale: locale}
end
end
@ -78,7 +78,7 @@ describe ApplicationController do
describe 'GET #welcome' do
before { get :welcome }
expect_status(200)
expect_http_status(:ok)
expect_template(:welcome)
end
end

View File

@ -25,7 +25,7 @@ describe CodeOcean::FilesController do
end
expect_json
expect_status(201)
expect_http_status(:created)
end
context 'with an invalid file' do
@ -36,7 +36,7 @@ describe CodeOcean::FilesController do
expect_assigns(file: CodeOcean::File)
expect_json
expect_status(422)
expect_http_status(:unprocessable_entity)
end
end

View File

@ -6,7 +6,7 @@ describe CodeharborLinksController do
let(:user) { create(:teacher) }
let(:codeocean_config) { instance_double(CodeOcean::Config) }
let(:codeharbor_config) { {codeharbor: {enabled: true, url: 'http://test.url'}} }
let(:codeharbor_config) { {codeharbor: {enabled: true, url: 'https://test.url'}} }
before do
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
@ -19,7 +19,7 @@ describe CodeharborLinksController do
get :new
end
expect_status(200)
expect_http_status(:ok)
end
describe 'GET #edit' do
@ -27,12 +27,12 @@ describe CodeharborLinksController do
before { get :edit, params: {id: codeharbor_link.id} }
expect_status(200)
expect_http_status(:ok)
end
describe 'POST #create' do
let(:post_request) { post :create, params: {codeharbor_link: params} }
let(:params) { {push_url: 'http://foo.bar/push', check_uuid_url: 'http://foo.bar/check', api_key: 'api_key'} }
let(:params) { {push_url: 'https://foo.bar/push', check_uuid_url: 'https://foo.bar/check', api_key: 'api_key'} }
it 'creates a codeharbor_link' do
expect { post_request }.to change(CodeharborLink, :count).by(1)
@ -59,14 +59,14 @@ describe CodeharborLinksController do
describe 'PUT #update' do
let(:codeharbor_link) { create(:codeharbor_link, user: user) }
let(:put_request) { patch :update, params: {id: codeharbor_link.id, codeharbor_link: params} }
let(:params) { {push_url: 'http://foo.bar/push', check_uuid_url: 'http://foo.bar/check', api_key: 'api_key'} }
let(:params) { {push_url: 'https://foo.bar/push', check_uuid_url: 'https://foo.bar/check', api_key: 'api_key'} }
it 'updates push_url' do
expect { put_request }.to change { codeharbor_link.reload.push_url }.to('http://foo.bar/push')
expect { put_request }.to change { codeharbor_link.reload.push_url }.to('https://foo.bar/push')
end
it 'updates check_uuid_url' do
expect { put_request }.to change { codeharbor_link.reload.check_uuid_url }.to('http://foo.bar/check')
expect { put_request }.to change { codeharbor_link.reload.check_uuid_url }.to('https://foo.bar/check')
end
it 'updates api_key' do

View File

@ -0,0 +1,42 @@
# frozen_string_literal: true
require 'rails_helper'
describe CommentsController do
let(:user) { create(:learner) }
let(:rfc_with_comment) { create(:rfc_with_comment, user: user) }
let(:comment) { rfc_with_comment.comments.first }
let(:updated_comment) { comment.reload }
let(:perform_request) { proc { put :update, format: :json, params: {id: comment.id, comment: comment_params} } }
before do
allow(controller).to receive(:current_user).and_return(user)
perform_request.call
end
describe 'PUT #update' do
context 'with valid params' do
let(:comment_params) { {text: 'test100'} }
it 'saves the permitted changes' do
expect(updated_comment.text).to eq('test100')
end
expect_http_status(:ok)
end
context 'with additional params' do
let(:comment_params) { {text: 'test100', row: 5, file_id: 50} }
it 'applies the permitted changes' do
expect(updated_comment.row).not_to eq(5)
expect(updated_comment.file_id).not_to eq(50)
expect(updated_comment.row).to eq(1)
expect(updated_comment.file_id).to eq(comment.file_id)
expect(updated_comment.text).to eq('test100')
end
expect_http_status(:ok)
end
end
end

View File

@ -27,7 +27,7 @@ describe ConsumersController do
before { post :create, params: {consumer: {}} }
expect_assigns(consumer: Consumer)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
end
@ -49,7 +49,7 @@ describe ConsumersController do
before { get :edit, params: {id: consumer.id} }
expect_assigns(consumer: Consumer)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
@ -60,7 +60,7 @@ describe ConsumersController do
end
expect_assigns(consumers: Consumer.all)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -68,7 +68,7 @@ describe ConsumersController do
before { get :new }
expect_assigns(consumer: Consumer)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
@ -76,7 +76,7 @@ describe ConsumersController do
before { get :show, params: {id: consumer.id} }
expect_assigns(consumer: :consumer)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
@ -92,7 +92,7 @@ describe ConsumersController do
before { put :update, params: {consumer: {name: ''}, id: consumer.id} }
expect_assigns(consumer: Consumer)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
end

View File

@ -10,13 +10,13 @@ describe ErrorTemplateAttributesController do
it 'gets index' do
get :index
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
expect(assigns(:error_template_attributes)).not_to be_nil
end
it 'gets new' do
get :new
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
it 'creates error_template_attribute' do
@ -26,12 +26,12 @@ describe ErrorTemplateAttributesController do
it 'shows error_template_attribute' do
get :show, params: {id: error_template_attribute}
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
it 'gets edit' do
get :edit, params: {id: error_template_attribute}
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
it 'updates error_template_attribute' do

View File

@ -10,13 +10,13 @@ describe ErrorTemplatesController do
it 'gets index' do
get :index
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
expect(assigns(:error_templates)).not_to be_nil
end
it 'gets new' do
get :new
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
it 'creates error_template' do
@ -26,12 +26,12 @@ describe ErrorTemplatesController do
it 'shows error_template' do
get :show, params: {id: error_template}
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
it 'gets edit' do
get :edit, params: {id: error_template}
expect(response.status).to eq(200)
expect(response).to have_http_status(:ok)
end
it 'updates error_template' do

View File

@ -20,20 +20,20 @@ describe EventsController do
expect { perform_request.call }.to change(Event, :count).by(1)
end
expect_status(201)
expect_http_status(:created)
end
context 'with an invalid event' do
before { post :create, params: {event: {exercise_id: 847_482}} }
expect_assigns(event: Event)
expect_status(422)
expect_http_status(:unprocessable_entity)
end
context 'with no event' do
before { post :create }
expect_status(422)
expect_http_status(:unprocessable_entity)
end
end
end

View File

@ -18,7 +18,7 @@ describe ExecutionEnvironmentsController do
before do
allow(Rails.env).to receive(:test?).and_return(false, true)
allow(Runner.strategy_class).to receive(:sync_environment).and_return(true)
runner = instance_double 'runner'
runner = instance_double Runner
allow(Runner).to receive(:for).and_return(runner)
allow(runner).to receive(:execute_command).and_return({})
perform_request.call
@ -46,7 +46,7 @@ describe ExecutionEnvironmentsController do
end
expect_assigns(execution_environment: ExecutionEnvironment)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
it 'does not register the execution environment with the runner management' do
@ -82,7 +82,7 @@ describe ExecutionEnvironmentsController do
expect_assigns(docker_images: Array)
expect_assigns(execution_environment: :execution_environment)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
@ -90,7 +90,7 @@ describe ExecutionEnvironmentsController do
let(:command) { 'which ruby' }
before do
runner = instance_double 'runner'
runner = instance_double Runner
allow(Runner).to receive(:for).with(user, execution_environment).and_return runner
allow(runner).to receive(:execute_command).and_return({})
post :execute_command, params: {command: command, id: execution_environment.id}
@ -98,7 +98,7 @@ describe ExecutionEnvironmentsController do
expect_assigns(execution_environment: :execution_environment)
expect_json
expect_status(200)
expect_http_status(:ok)
end
describe 'GET #index' do
@ -108,7 +108,7 @@ describe ExecutionEnvironmentsController do
end
expect_assigns(execution_environments: ExecutionEnvironment.all)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -119,7 +119,7 @@ describe ExecutionEnvironmentsController do
expect_assigns(docker_images: Array)
expect_assigns(execution_environment: ExecutionEnvironment)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
@ -158,7 +158,7 @@ describe ExecutionEnvironmentsController do
before { get :shell, params: {id: execution_environment.id} }
expect_assigns(execution_environment: :execution_environment)
expect_status(200)
expect_http_status(:ok)
expect_template(:shell)
end
@ -166,7 +166,7 @@ describe ExecutionEnvironmentsController do
before { get :statistics, params: {id: execution_environment.id} }
expect_assigns(execution_environment: :execution_environment)
expect_status(200)
expect_http_status(:ok)
expect_template(:statistics)
end
@ -174,7 +174,7 @@ describe ExecutionEnvironmentsController do
before { get :show, params: {id: execution_environment.id} }
expect_assigns(execution_environment: :execution_environment)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
@ -183,7 +183,7 @@ describe ExecutionEnvironmentsController do
before do
allow(Rails.env).to receive(:test?).and_return(false, true)
allow(Runner.strategy_class).to receive(:sync_environment).and_return(true)
runner = instance_double 'runner'
runner = instance_double Runner
allow(Runner).to receive(:for).and_return(runner)
allow(runner).to receive(:execute_command).and_return({})
put :update, params: {execution_environment: attributes_for(:ruby, pool_size: 1), id: execution_environment.id}
@ -206,7 +206,7 @@ describe ExecutionEnvironmentsController do
end
expect_assigns(execution_environment: ExecutionEnvironment)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
it 'does not update the execution environment at the runner management' do

View File

@ -20,7 +20,7 @@ describe ExercisesController do
end
expect_json
expect_status(200)
expect_http_status(:ok)
end
describe 'POST #clone' do
@ -122,7 +122,7 @@ describe ExercisesController do
before { post :create, params: {exercise: {}} }
expect_assigns(exercise: Exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
end
@ -144,7 +144,7 @@ describe ExercisesController do
before { get :edit, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
@ -173,7 +173,7 @@ describe ExercisesController do
end
end
expect_status(200)
expect_http_status(:ok)
expect_template(:implement)
end
@ -195,7 +195,7 @@ describe ExercisesController do
end
expect_assigns(exercises: :scope)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -204,7 +204,7 @@ describe ExercisesController do
expect_assigns(execution_environments: ExecutionEnvironment.all, exercise: Exercise)
expect_assigns(exercise: Exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
@ -213,7 +213,7 @@ describe ExercisesController do
before { get :show, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
end
@ -223,7 +223,7 @@ describe ExercisesController do
before { get :reload, format: :json, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:reload)
end
end
@ -232,10 +232,44 @@ describe ExercisesController do
before { get :statistics, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:statistics)
end
describe 'GET #external_user_statistics' do
let(:perform_request) { get :external_user_statistics, params: params }
let(:params) { {id: exercise.id, external_user_id: external_user.id} }
let(:external_user) { create(:external_user) }
before do
2.times { create(:submission, cause: 'autosave', user: external_user, exercise: exercise) }
2.times { create(:submission, cause: 'run', user: external_user, exercise: exercise) }
create(:submission, cause: 'assess', user: external_user, exercise: exercise)
end
context 'when viewing the default submission statistics page without a parameter' do
it 'does not list autosaved submissions' do
perform_request
expect(assigns(:all_events).filter {|event| event.is_a? Submission }).to match_array [
an_object_having_attributes(cause: 'run', user_id: external_user.id),
an_object_having_attributes(cause: 'assess', user_id: external_user.id),
an_object_having_attributes(cause: 'run', user_id: external_user.id),
]
end
end
context 'when including autosaved submissions via the query parameter' do
let(:params) { super().merge(show_autosaves: 'true') }
it 'lists all submissions, including autosaved submissions' do
perform_request
submissions = assigns(:all_events).filter {|event| event.is_a? Submission }
expect(submissions).to match_array Submission.all
expect(submissions).to include an_object_having_attributes(cause: 'autosave', user_id: external_user.id)
end
end
end
describe 'POST #submit' do
let(:output) { {} }
let(:perform_request) { post :submit, format: :json, params: {id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id}} }
@ -285,7 +319,7 @@ describe ExercisesController do
end
expect_json
expect_status(200)
expect_http_status(:ok)
end
context 'when the score transmission fails' do
@ -301,7 +335,7 @@ describe ExercisesController do
end
expect_json
expect_status(503)
expect_http_status(:service_unavailable)
end
end
@ -322,7 +356,7 @@ describe ExercisesController do
end
expect_json
expect_status(200)
expect_http_status(:ok)
end
end
@ -340,7 +374,7 @@ describe ExercisesController do
before { put :update, params: {exercise: {title: ''}, id: exercise.id} }
expect_assigns(exercise: Exercise)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
end

View File

@ -12,7 +12,7 @@ describe ExternalUsersController do
before { get :index }
expect_assigns(users: ExternalUser.all)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -20,7 +20,7 @@ describe ExternalUsersController do
before { get :show, params: {id: users.first.id} }
expect_assigns(user: ExternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
end

View File

@ -29,7 +29,7 @@ describe FileTypesController do
expect_assigns(editor_modes: Array)
expect_assigns(file_type: FileType)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
end
@ -52,7 +52,7 @@ describe FileTypesController do
expect_assigns(editor_modes: Array)
expect_assigns(file_type: FileType)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
@ -63,7 +63,7 @@ describe FileTypesController do
end
expect_assigns(file_types: FileType.all)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -72,7 +72,7 @@ describe FileTypesController do
expect_assigns(editor_modes: Array)
expect_assigns(file_type: FileType)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
@ -80,7 +80,7 @@ describe FileTypesController do
before { get :show, params: {id: file_type.id} }
expect_assigns(file_type: :file_type)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
@ -98,7 +98,7 @@ describe FileTypesController do
expect_assigns(editor_modes: Array)
expect_assigns(file_type: FileType)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
end

View File

@ -33,7 +33,7 @@ describe InternalUsersController do
before { get :activate, params: {id: user.id, token: user.activation_token} }
expect_assigns(user: InternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:activate)
end
end
@ -135,10 +135,10 @@ describe InternalUsersController do
end
context 'with an invalid internal user' do
before { post :create, params: {internal_user: {}} }
before { post :create, params: {internal_user: {invalid_attribute: 'a string'}} }
expect_assigns(user: InternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
end
@ -165,7 +165,7 @@ describe InternalUsersController do
end
expect_assigns(user: InternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
@ -178,7 +178,7 @@ describe InternalUsersController do
get :forgot_password
end
expect_status(200)
expect_http_status(:ok)
expect_template(:forgot_password)
end
@ -213,7 +213,7 @@ describe InternalUsersController do
context 'without an email address' do
before { post :forgot_password }
expect_status(200)
expect_http_status(:ok)
expect_template(:forgot_password)
end
end
@ -225,7 +225,7 @@ describe InternalUsersController do
end
expect_assigns(users: InternalUser.all)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -236,7 +236,7 @@ describe InternalUsersController do
end
expect_assigns(user: InternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end
@ -256,7 +256,7 @@ describe InternalUsersController do
end
expect_assigns(user: :user)
expect_status(200)
expect_http_status(:ok)
expect_template(:reset_password)
end
end
@ -295,7 +295,7 @@ describe InternalUsersController do
end
expect_assigns(user: :user)
expect_status(200)
expect_http_status(:ok)
expect_template(:reset_password)
end
end
@ -308,7 +308,7 @@ describe InternalUsersController do
end
expect_assigns(user: InternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
@ -326,7 +326,7 @@ describe InternalUsersController do
before { put :update, params: {internal_user: {email: ''}, id: users.first.id} }
expect_assigns(user: InternalUser)
expect_status(200)
expect_http_status(:ok)
expect_template(:edit)
end
end

View File

@ -35,14 +35,14 @@ describe RequestForCommentsController do
describe 'GET #my_comment_requests' do
before { get :my_comment_requests }
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
describe 'GET #rfcs_with_my_comments' do
before { get :rfcs_with_my_comments }
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -52,7 +52,7 @@ describe RequestForCommentsController do
get :rfcs_for_exercise, params: {exercise_id: exercise.id}
end
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
end

View File

@ -86,9 +86,9 @@ describe SessionsController do
it 'sets the specified locale' do
expect(controller).to receive(:switch_locale).and_call_original
i18n = instance_double 'i18n', locale: locale.to_s
i18n = class_double I18n, locale: locale
allow(I18n).to receive(:locale=).with(I18n.default_locale).and_call_original
allow(I18n).to receive(:locale=).with(locale.to_s).and_return(i18n)
allow(I18n).to receive(:locale=).with(locale).and_return(i18n)
perform_request
expect(i18n.locale.to_sym).to eq(locale)
end
@ -201,13 +201,14 @@ describe SessionsController do
end
describe 'GET #destroy_through_lti' do
let(:perform_request) { proc { get :destroy_through_lti, params: {consumer_id: consumer.id, submission_id: submission.id} } }
let(:perform_request) { proc { get :destroy_through_lti, params: {submission_id: submission.id} } }
let(:submission) { create(:submission, exercise: create(:dummy)) }
before do
# Todo replace session with lti_parameter
# Todo create LtiParameter Object
# session[:lti_parameters] = {}
allow(controller).to receive(:current_user).and_return(submission.user)
perform_request.call
end
@ -217,7 +218,7 @@ describe SessionsController do
perform_request.call
end
expect_status(200)
expect_http_status(:ok)
expect_template(:destroy_through_lti)
end
@ -230,7 +231,7 @@ describe SessionsController do
get :new
end
expect_status(200)
expect_http_status(:ok)
expect_template(:new)
end

View File

@ -11,7 +11,7 @@ describe StatisticsController do
describe "GET ##{route}" do
before { get route }
expect_status(200)
expect_http_status(:ok)
expect_template(route)
end
end
@ -20,7 +20,7 @@ describe StatisticsController do
describe "GET ##{route}" do
before { get route }
expect_status(200)
expect_http_status(:ok)
expect_template(:activity_history)
end
end
@ -29,7 +29,7 @@ describe StatisticsController do
describe "GET ##{route}.json" do
before { get route, format: :json }
expect_status(200)
expect_http_status(:ok)
expect_json
end
end

View File

@ -26,7 +26,7 @@ describe SubmissionsController do
end
expect_json
expect_status(201)
expect_http_status(:created)
end
context 'with an invalid submission' do
@ -34,7 +34,7 @@ describe SubmissionsController do
expect_assigns(submission: Submission)
expect_json
expect_status(422)
expect_http_status(:unprocessable_entity)
end
end
@ -42,7 +42,7 @@ describe SubmissionsController do
context 'with an invalid filename' do
before { get :download_file, params: {filename: SecureRandom.hex, id: submission.id} }
expect_status(404)
expect_http_status(:not_found)
end
context 'with a valid binary filename' do
@ -56,7 +56,7 @@ describe SubmissionsController do
expect_assigns(file: :file)
expect_assigns(submission: :submission)
expect_content_type('application/octet-stream')
expect_status(200)
expect_http_status(:ok)
it 'sets the correct filename' do
expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"")
@ -75,7 +75,7 @@ describe SubmissionsController do
expect_assigns(file: :file)
expect_assigns(submission: :submission)
expect_content_type('video/mp4')
expect_status(200)
expect_http_status(:ok)
it 'sets the correct filename' do
expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"")
@ -88,7 +88,7 @@ describe SubmissionsController do
expect_assigns(file: :file)
expect_assigns(submission: :submission)
expect_content_type('text/javascript')
expect_status(200)
expect_http_status(:ok)
it 'sets the correct filename' do
expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"")
@ -104,7 +104,7 @@ describe SubmissionsController do
end
expect_assigns(submissions: Submission.all)
expect_status(200)
expect_http_status(:ok)
expect_template(:index)
end
@ -114,7 +114,7 @@ describe SubmissionsController do
context 'with an invalid filename' do
before { get :render_file, params: {filename: SecureRandom.hex, id: submission.id} }
expect_status(404)
expect_http_status(:not_found)
end
context 'with a valid filename' do
@ -128,10 +128,10 @@ describe SubmissionsController do
expect_assigns(file: :file)
expect_assigns(submission: :submission)
expect_content_type('video/mp4')
expect_status(200)
expect_http_status(:ok)
it 'renders the file content' do
expect(response.body).to eq(file.native_file.read)
expect(response.body).to eq(file.read)
end
end
@ -141,7 +141,7 @@ describe SubmissionsController do
expect_assigns(file: :file)
expect_assigns(submission: :submission)
expect_content_type('text/javascript')
expect_status(200)
expect_http_status(:ok)
it 'renders the file content' do
expect(response.body).to eq(file.content)
@ -151,15 +151,20 @@ describe SubmissionsController do
end
describe 'GET #run' do
let(:filename) { submission.collect_files.detect(&:main_file?).name_with_extension }
let(:perform_request) { get :run, params: {filename: filename, id: submission.id} }
let(:file) { submission.collect_files.detect(&:main_file?) }
let(:perform_request) { get :run, format: :json, params: {filename: file.filepath, id: submission.id} }
context 'when no errors occur during execution' do
before do
allow_any_instance_of(described_class).to receive(:hijack)
allow_any_instance_of(Submission).to receive(:run).and_return({})
allow_any_instance_of(described_class).to receive(:save_testrun_output)
perform_request
end
pending('todo')
expect_assigns(submission: :submission)
expect_assigns(file: :file)
expect_http_status(204)
end
end
@ -167,7 +172,7 @@ describe SubmissionsController do
before { get :show, params: {id: submission.id} }
expect_assigns(submission: :submission)
expect_status(200)
expect_http_status(:ok)
expect_template(:show)
end
@ -179,7 +184,7 @@ describe SubmissionsController do
before { get :show, params: {id: submission.id}, format: :json }
expect_assigns(submission: :submission)
expect_status(200)
expect_http_status(:ok)
%i[render run test].each do |action|
describe "##{action}_url" do
@ -206,21 +211,29 @@ describe SubmissionsController do
end
describe 'GET #score' do
let(:perform_request) { proc { get :score, params: {id: submission.id} } }
let(:perform_request) { proc { get :score, format: :json, params: {id: submission.id} } }
before { perform_request.call }
before do
allow_any_instance_of(described_class).to receive(:hijack)
perform_request.call
end
pending('todo: mock puma webserver or encapsulate tubesock call (Tubesock::HijackNotAvailable)')
expect_assigns(submission: :submission)
expect_http_status(204)
end
describe 'GET #test' do
let(:filename) { submission.collect_files.detect(&:teacher_defined_assessment?).name_with_extension }
let(:file) { submission.collect_files.detect(&:teacher_defined_assessment?) }
let(:output) { {} }
before do
get :test, params: {filename: filename, id: submission.id}
file.update(hidden: false)
allow_any_instance_of(described_class).to receive(:hijack)
get :test, params: {filename: "#{file.filepath}.json", id: submission.id}
end
pending('todo')
expect_assigns(submission: :submission)
expect_assigns(file: :file)
expect_http_status(204)
end
end