Merge branch 'master' into refactor_proforma_import_export

This commit is contained in:
Karol
2022-09-13 22:47:50 +02:00
67 changed files with 1199 additions and 601 deletions

View File

@ -7,6 +7,26 @@ describe CodeOcean::FilesController do
before { allow(controller).to receive(:current_user).and_return(user) }
describe 'GET #show_protected_upload' do
context 'with a valid filename' do
let(:submission) { create(:submission, exercise: create(:audio_video)) }
before { get :show_protected_upload, params: {filename: file.name_with_extension, id: file.id} }
context 'with a binary file' do
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } }
expect_assigns(file: :file)
expect_content_type('video/mp4')
expect_http_status(:ok)
it 'sets the correct filename' do
expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"")
end
end
end
end
describe 'POST #create' do
let(:submission) { create(:submission, user: user) }

View File

@ -6,7 +6,10 @@ describe ExercisesController do
let(:exercise) { create(:dummy) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
before do
create(:test_file, context: exercise)
allow(controller).to receive(:current_user).and_return(user)
end
describe 'PUT #batch_update' do
let(:attributes) { {public: 'true'} }
@ -184,6 +187,17 @@ describe ExercisesController do
expect_flash_message(:alert, :'exercises.implement.no_files')
expect_redirect(:exercise)
end
context 'with other users accessing an unpublished exercise' do
let(:exercise) { create(:fibonacci, unpublished: true) }
let(:user) { create(:teacher) }
before { perform_request.call }
expect_assigns(exercise: :exercise)
expect_flash_message(:alert, :'exercises.implement.unpublished')
expect_redirect(:exercise)
end
end
describe 'GET #index' do
@ -220,6 +234,8 @@ describe ExercisesController do
describe 'GET #reload' do
context 'when being anyone' do
let(:exercise) { create(:fibonacci) }
before { get :reload, format: :json, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)

View File

@ -74,11 +74,9 @@ describe SubmissionsController do
expect_assigns(file: :file)
expect_assigns(submission: :submission)
expect_content_type('video/mp4')
expect_http_status(:ok)
it 'sets the correct filename' do
expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"")
it 'sets the correct redirect' do
expect(response.location).to eq protected_upload_url(id: file, filename: file.name_with_extension)
end
end