Upgrade Rails to version 5.2.1 and adopt code & specs where necessary
Signed-off-by: Sebastian Serth <Sebastian.Serth@student.hpi.de>
This commit is contained in:
@ -12,7 +12,7 @@ describe SubmissionsController do
|
||||
|
||||
context 'with a valid submission' do
|
||||
let(:exercise) { FactoryBot.create(:hello_world) }
|
||||
let(:request) { proc { post :create, format: :json, submission: FactoryBot.attributes_for(:submission, exercise_id: exercise.id) } }
|
||||
let(:request) { proc { post :create, format: :json, params: { submission: FactoryBot.attributes_for(:submission, exercise_id: exercise.id) } } }
|
||||
before(:each) { request.call }
|
||||
|
||||
expect_assigns(submission: Submission)
|
||||
@ -26,7 +26,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
context 'with an invalid submission' do
|
||||
before(:each) { post :create, submission: {} }
|
||||
before(:each) { post :create, params: { submission: { } } }
|
||||
|
||||
expect_assigns(submission: Submission)
|
||||
expect_json
|
||||
@ -36,21 +36,39 @@ describe SubmissionsController do
|
||||
|
||||
describe 'GET #download_file' do
|
||||
context 'with an invalid filename' do
|
||||
before(:each) { get :download_file, filename: SecureRandom.hex, id: submission.id }
|
||||
before(:each) { get :download_file, params: { filename: SecureRandom.hex, id: submission.id } }
|
||||
|
||||
expect_status(404)
|
||||
end
|
||||
|
||||
context 'with a valid binary filename' do
|
||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:sql_select)) }
|
||||
before(:each) { get :download_file, params: { filename: file.name_with_extension, id: submission.id } }
|
||||
|
||||
context 'for a binary file' do
|
||||
let(:file) { submission.collect_files.detect { |file| file.name == 'exercise' && file.file_type.file_extension == '.sql' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
expect_content_type('application/octet-stream')
|
||||
expect_status(200)
|
||||
|
||||
it 'sets the correct filename' do
|
||||
expect(response.headers['Content-Disposition']).to eq("attachment; filename=\"#{file.name_with_extension}\"")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a valid filename' do
|
||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
|
||||
before(:each) { get :download_file, filename: file.name_with_extension, id: submission.id }
|
||||
before(:each) { get :download_file, params: { filename: file.name_with_extension, id: submission.id } }
|
||||
|
||||
context 'for a binary file' do
|
||||
let(:file) { submission.collect_files.detect { |file| file.file_type.file_extension == '.mp4' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
expect_content_type('application/octet-stream')
|
||||
expect_content_type('video/mp4')
|
||||
expect_status(200)
|
||||
|
||||
it 'sets the correct filename' do
|
||||
@ -86,21 +104,21 @@ describe SubmissionsController do
|
||||
let(:file) { submission.files.first }
|
||||
|
||||
context 'with an invalid filename' do
|
||||
before(:each) { get :render_file, filename: SecureRandom.hex, id: submission.id }
|
||||
before(:each) { get :render_file, params: { filename: SecureRandom.hex, id: submission.id } }
|
||||
|
||||
expect_status(404)
|
||||
end
|
||||
|
||||
context 'with a valid filename' do
|
||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
|
||||
before(:each) { get :render_file, filename: file.name_with_extension, id: submission.id }
|
||||
before(:each) { get :render_file, params: { filename: file.name_with_extension, id: submission.id } }
|
||||
|
||||
context 'for a binary file' do
|
||||
let(:file) { submission.collect_files.detect { |file| file.file_type.file_extension == '.mp4' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
expect_content_type('application/octet-stream')
|
||||
expect_content_type('video/mp4')
|
||||
expect_status(200)
|
||||
|
||||
it 'renders the file content' do
|
||||
@ -125,7 +143,7 @@ describe SubmissionsController do
|
||||
|
||||
describe 'GET #run' do
|
||||
let(:filename) { submission.collect_files.detect(&:main_file?).name_with_extension }
|
||||
let(:request) { get :run, filename: filename, id: submission.id }
|
||||
let(:request) { get :run, params: { filename: filename }, id: submission.id }
|
||||
|
||||
before(:each) do
|
||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:write).at_least(3).times
|
||||
@ -176,7 +194,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, id: submission.id }
|
||||
before(:each) { get :show, params: { id: submission.id } }
|
||||
|
||||
expect_assigns(submission: :submission)
|
||||
expect_status(200)
|
||||
@ -188,7 +206,7 @@ describe SubmissionsController do
|
||||
# https://github.com/rails/jbuilder/issues/32
|
||||
render_views
|
||||
|
||||
before(:each) { get :show, id: submission.id, format: :json }
|
||||
before(:each) { get :show, params: { id: submission.id }, format: :json }
|
||||
expect_assigns(submission: :submission)
|
||||
expect_status(200)
|
||||
|
||||
@ -219,14 +237,14 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
describe 'GET #score' do
|
||||
let(:request) { proc { get :score, id: submission.id } }
|
||||
let(:request) { proc { get :score, params: { id: submission.id } } }
|
||||
before(:each) { request.call }
|
||||
|
||||
pending("todo: mock puma webserver or encapsulate tubesock call (Tubesock::HijackNotAvailable)")
|
||||
end
|
||||
|
||||
describe 'POST #stop' do
|
||||
let(:request) { proc { post :stop, container_id: CONTAINER.id, id: submission.id } }
|
||||
let(:request) { proc { post :stop, params: { container_id: CONTAINER.id, id: submission.id } } }
|
||||
|
||||
context 'when the container can be found' do
|
||||
before(:each) do
|
||||
@ -269,7 +287,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
describe '#with_server_sent_events' do
|
||||
let(:response) { ActionController::TestResponse.new }
|
||||
let(:response) { ActionDispatch::TestResponse.new }
|
||||
before(:each) { allow(controller).to receive(:response).and_return(response) }
|
||||
|
||||
context 'when no error occurs' do
|
||||
|
Reference in New Issue
Block a user