Apply automatic rubocop fixes
This commit is contained in:
@ -1,18 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::DashboardController do
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:admin)) }
|
||||
before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:admin)) }
|
||||
|
||||
describe 'GET #show' do
|
||||
describe 'with format HTML' do
|
||||
before(:each) { get :show }
|
||||
before { get :show }
|
||||
|
||||
expect_status(200)
|
||||
expect_template(:show)
|
||||
end
|
||||
|
||||
describe 'with format JSON' do
|
||||
before(:each) { get :show, format: :json }
|
||||
before { get :show, format: :json }
|
||||
|
||||
expect_json
|
||||
expect_status(200)
|
||||
|
@ -1,10 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ApplicationController do
|
||||
describe '#current_user' do
|
||||
context 'with an external user' do
|
||||
let(:external_user) { FactoryBot.create(:external_user) }
|
||||
before(:each) { session[:external_user_id] = external_user.id }
|
||||
|
||||
before { session[:external_user_id] = external_user.id }
|
||||
|
||||
it 'returns the external user' do
|
||||
expect(controller.current_user).to eq(external_user)
|
||||
@ -13,7 +16,8 @@ describe ApplicationController do
|
||||
|
||||
context 'without an external user' do
|
||||
let(:internal_user) { FactoryBot.create(:teacher) }
|
||||
before(:each) { login_user(internal_user) }
|
||||
|
||||
before { login_user(internal_user) }
|
||||
|
||||
it 'returns the internal user' do
|
||||
expect(controller.current_user).to eq(internal_user)
|
||||
@ -22,7 +26,7 @@ describe ApplicationController do
|
||||
end
|
||||
|
||||
describe '#render_not_authorized' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:welcome) { controller.send(:render_not_authorized) }
|
||||
get :welcome
|
||||
end
|
||||
@ -35,19 +39,19 @@ describe ApplicationController do
|
||||
let(:locale) { :de }
|
||||
|
||||
context 'when specifying a locale' do
|
||||
before(:each) { allow(session).to receive(:[]=).at_least(:once) }
|
||||
before { allow(session).to receive(:[]=).at_least(:once) }
|
||||
|
||||
context "using the 'custom_locale' parameter" do
|
||||
it 'overwrites the session' do
|
||||
expect(session).to receive(:[]=).with(:locale, locale.to_s)
|
||||
get :welcome, params: { custom_locale: locale }
|
||||
get :welcome, params: {custom_locale: locale}
|
||||
end
|
||||
end
|
||||
|
||||
context "using the 'locale' parameter" do
|
||||
it 'overwrites the session' do
|
||||
expect(session).to receive(:[]=).with(:locale, locale.to_s)
|
||||
get :welcome, params: { locale: locale }
|
||||
get :welcome, params: {locale: locale}
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -70,7 +74,7 @@ describe ApplicationController do
|
||||
end
|
||||
|
||||
describe 'GET #welcome' do
|
||||
before(:each) { get :welcome }
|
||||
before { get :welcome }
|
||||
|
||||
expect_status(200)
|
||||
expect_template(:welcome)
|
||||
|
@ -4,14 +4,16 @@ require 'rails_helper'
|
||||
|
||||
describe CodeOcean::FilesController do
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:submission) { FactoryBot.create(:submission, user: user) }
|
||||
|
||||
context 'with a valid file' do
|
||||
let(:perform_request) { proc { post :create, params: { code_ocean_file: FactoryBot.build(:file, context: submission).attributes, format: :json } } }
|
||||
before(:each) do
|
||||
let(:perform_request) { proc { post :create, params: {code_ocean_file: FactoryBot.build(:file, context: submission).attributes, format: :json} } }
|
||||
|
||||
before do
|
||||
submission.exercise.update(allow_file_creation: true)
|
||||
perform_request.call
|
||||
end
|
||||
@ -27,9 +29,9 @@ describe CodeOcean::FilesController do
|
||||
end
|
||||
|
||||
context 'with an invalid file' do
|
||||
before(:each) do
|
||||
before do
|
||||
submission.exercise.update(allow_file_creation: true)
|
||||
post :create, params: { code_ocean_file: {context_id: submission.id, context_type: Submission}, format: :json }
|
||||
post :create, params: {code_ocean_file: {context_id: submission.id, context_type: Submission}, format: :json}
|
||||
end
|
||||
|
||||
expect_assigns(file: CodeOcean::File)
|
||||
@ -40,8 +42,9 @@ describe CodeOcean::FilesController do
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
let(:perform_request) { proc { delete :destroy, params: { id: exercise.files.first.id } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { delete :destroy, params: {id: exercise.files.first.id} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(file: CodeOcean::File)
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ConsumersController do
|
||||
let(:consumer) { FactoryBot.create(:consumer) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with a valid consumer' do
|
||||
let(:perform_request) { proc { post :create, params: { consumer: FactoryBot.attributes_for(:consumer) } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, params: {consumer: FactoryBot.attributes_for(:consumer)} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
|
||||
@ -20,7 +24,7 @@ describe ConsumersController do
|
||||
end
|
||||
|
||||
context 'with an invalid consumer' do
|
||||
before(:each) { post :create, params: { consumer: {} } }
|
||||
before { post :create, params: {consumer: {}} }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
expect_status(200)
|
||||
@ -29,20 +33,20 @@ describe ConsumersController do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) { delete :destroy, params: { id: consumer.id } }
|
||||
before { delete :destroy, params: {id: consumer.id} }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
|
||||
it 'destroys the consumer' do
|
||||
consumer = FactoryBot.create(:consumer)
|
||||
expect { delete :destroy, params: { id: consumer.id } }.to change(Consumer, :count).by(-1)
|
||||
expect { delete :destroy, params: {id: consumer.id} }.to change(Consumer, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:consumers)
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) { get :edit, params: { id: consumer.id } }
|
||||
before { get :edit, params: {id: consumer.id} }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
expect_status(200)
|
||||
@ -51,7 +55,8 @@ describe ConsumersController do
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:consumers) { FactoryBot.create_pair(:consumer) }
|
||||
before(:each) { get :index }
|
||||
|
||||
before { get :index }
|
||||
|
||||
expect_assigns(consumers: Consumer.all)
|
||||
expect_status(200)
|
||||
@ -59,7 +64,7 @@ describe ConsumersController do
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) { get :new }
|
||||
before { get :new }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
expect_status(200)
|
||||
@ -67,7 +72,7 @@ describe ConsumersController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, params: { id: consumer.id } }
|
||||
before { get :show, params: {id: consumer.id} }
|
||||
|
||||
expect_assigns(consumer: :consumer)
|
||||
expect_status(200)
|
||||
@ -76,14 +81,14 @@ describe ConsumersController do
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid consumer' do
|
||||
before(:each) { put :update, params: { consumer: FactoryBot.attributes_for(:consumer), id: consumer.id } }
|
||||
before { put :update, params: {consumer: FactoryBot.attributes_for(:consumer), id: consumer.id} }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
expect_redirect(:consumer)
|
||||
end
|
||||
|
||||
context 'with an invalid consumer' do
|
||||
before(:each) { put :update, params: { consumer: {name: ''}, id: consumer.id } }
|
||||
before { put :update, params: {consumer: {name: ''}, id: consumer.id} }
|
||||
|
||||
expect_assigns(consumer: Consumer)
|
||||
expect_status(200)
|
||||
|
@ -1,43 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ErrorTemplateAttributesController do
|
||||
let!(:error_template_attribute) { FactoryBot.create(:error_template_attribute) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
it "should get index" do
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
it 'gets index' do
|
||||
get :index
|
||||
expect(response.status).to eq(200)
|
||||
expect(assigns(:error_template_attributes)).not_to be_nil
|
||||
end
|
||||
|
||||
it "should get new" do
|
||||
it 'gets new' do
|
||||
get :new
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "should create error_template_attribute" do
|
||||
expect { post :create, params: { error_template_attribute: { } } }.to change(ErrorTemplateAttribute, :count).by(1)
|
||||
it 'creates error_template_attribute' do
|
||||
expect { post :create, params: {error_template_attribute: {}} }.to change(ErrorTemplateAttribute, :count).by(1)
|
||||
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
|
||||
end
|
||||
|
||||
it "should show error_template_attribute" do
|
||||
get :show, params: { id: error_template_attribute }
|
||||
it 'shows error_template_attribute' do
|
||||
get :show, params: {id: error_template_attribute}
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "should get edit" do
|
||||
get :edit, params: { id: error_template_attribute }
|
||||
it 'gets edit' do
|
||||
get :edit, params: {id: error_template_attribute}
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "should update error_template_attribute" do
|
||||
patch :update, params: { id: error_template_attribute, error_template_attribute: FactoryBot.attributes_for(:error_template_attribute) }
|
||||
it 'updates error_template_attribute' do
|
||||
patch :update, params: {id: error_template_attribute, error_template_attribute: FactoryBot.attributes_for(:error_template_attribute)}
|
||||
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
|
||||
end
|
||||
|
||||
it "should destroy error_template_attribute" do
|
||||
expect { delete :destroy, params: { id: error_template_attribute } }.to change(ErrorTemplateAttribute, :count).by(-1)
|
||||
it 'destroys error_template_attribute' do
|
||||
expect { delete :destroy, params: {id: error_template_attribute} }.to change(ErrorTemplateAttribute, :count).by(-1)
|
||||
expect(response).to redirect_to(error_template_attributes_path)
|
||||
end
|
||||
end
|
||||
|
@ -1,43 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ErrorTemplatesController do
|
||||
let!(:error_template) { FactoryBot.create(:error_template) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
it "should get index" do
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
it 'gets index' do
|
||||
get :index
|
||||
expect(response.status).to eq(200)
|
||||
expect(assigns(:error_templates)).not_to be_nil
|
||||
end
|
||||
|
||||
it "should get new" do
|
||||
it 'gets new' do
|
||||
get :new
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "should create error_template" do
|
||||
expect { post :create, params: {error_template: { execution_environment_id: error_template.execution_environment.id } } }.to change(ErrorTemplate, :count).by(1)
|
||||
it 'creates error_template' do
|
||||
expect { post :create, params: {error_template: {execution_environment_id: error_template.execution_environment.id}} }.to change(ErrorTemplate, :count).by(1)
|
||||
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
|
||||
end
|
||||
|
||||
it "should show error_template" do
|
||||
get :show, params: { id: error_template }
|
||||
it 'shows error_template' do
|
||||
get :show, params: {id: error_template}
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "should get edit" do
|
||||
get :edit, params: { id: error_template }
|
||||
it 'gets edit' do
|
||||
get :edit, params: {id: error_template}
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "should update error_template" do
|
||||
patch :update, params: { id: error_template, error_template: FactoryBot.attributes_for(:error_template) }
|
||||
it 'updates error_template' do
|
||||
patch :update, params: {id: error_template, error_template: FactoryBot.attributes_for(:error_template)}
|
||||
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
|
||||
end
|
||||
|
||||
it "should destroy error_template" do
|
||||
expect { delete :destroy, params: { id: error_template } }.to change(ErrorTemplate, :count).by(-1)
|
||||
it 'destroys error_template' do
|
||||
expect { delete :destroy, params: {id: error_template} }.to change(ErrorTemplate, :count).by(-1)
|
||||
expect(response).to redirect_to(error_templates_path)
|
||||
end
|
||||
end
|
||||
|
@ -1,14 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe EventsController do
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
let(:exercise) {FactoryBot.create(:fibonacci)}
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with a valid event' do
|
||||
let(:perform_request) { proc { post :create, params: { event: {category: 'foo', data: 'bar', exercise_id: exercise.id, file_id: exercise.files[0].id} } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, params: {event: {category: 'foo', data: 'bar', exercise_id: exercise.id, file_id: exercise.files[0].id}} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(event: Event)
|
||||
|
||||
@ -20,13 +24,15 @@ describe EventsController do
|
||||
end
|
||||
|
||||
context 'with an invalid event' do
|
||||
before(:each) { post :create, params: { event: {exercise_id: 847482} } }
|
||||
before { post :create, params: {event: {exercise_id: 847_482}} }
|
||||
|
||||
expect_assigns(event: Event)
|
||||
expect_status(422)
|
||||
end
|
||||
|
||||
context 'with no event' do
|
||||
before(:each) { post :create }
|
||||
before { post :create }
|
||||
|
||||
expect_status(422)
|
||||
end
|
||||
end
|
||||
|
@ -1,16 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExecutionEnvironmentsController do
|
||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
before(:each) { expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([]) }
|
||||
before { expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([]) }
|
||||
|
||||
context 'with a valid execution environment' do
|
||||
let(:perform_request) { proc { post :create, params: { execution_environment: FactoryBot.build(:ruby).attributes } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, params: {execution_environment: FactoryBot.build(:ruby).attributes} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(docker_images: Array)
|
||||
expect_assigns(execution_environment: ExecutionEnvironment)
|
||||
@ -23,7 +27,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
context 'with an invalid execution environment' do
|
||||
before(:each) { post :create, params: { execution_environment: {} } }
|
||||
before { post :create, params: {execution_environment: {}} }
|
||||
|
||||
expect_assigns(execution_environment: ExecutionEnvironment)
|
||||
expect_status(200)
|
||||
@ -32,22 +36,22 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) { delete :destroy, params: { id: execution_environment.id } }
|
||||
before { delete :destroy, params: {id: execution_environment.id} }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
|
||||
it 'destroys the execution environment' do
|
||||
execution_environment = FactoryBot.create(:ruby)
|
||||
expect { delete :destroy, params: { id: execution_environment.id } }.to change(ExecutionEnvironment, :count).by(-1)
|
||||
expect { delete :destroy, params: {id: execution_environment.id} }.to change(ExecutionEnvironment, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:execution_environments)
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([])
|
||||
get :edit, params: { id: execution_environment.id }
|
||||
get :edit, params: {id: execution_environment.id}
|
||||
end
|
||||
|
||||
expect_assigns(docker_images: Array)
|
||||
@ -59,10 +63,10 @@ describe ExecutionEnvironmentsController do
|
||||
describe 'POST #execute_command' do
|
||||
let(:command) { 'which ruby' }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect(DockerClient).to receive(:new).with(execution_environment: execution_environment).and_call_original
|
||||
expect_any_instance_of(DockerClient).to receive(:execute_arbitrary_command).with(command)
|
||||
post :execute_command, params: { command: command, id: execution_environment.id }
|
||||
post :execute_command, params: {command: command, id: execution_environment.id}
|
||||
end
|
||||
|
||||
expect_assigns(docker_client: DockerClient)
|
||||
@ -73,7 +77,8 @@ describe ExecutionEnvironmentsController do
|
||||
|
||||
describe 'GET #index' do
|
||||
before(:all) { FactoryBot.create_pair(:ruby) }
|
||||
before(:each) { get :index }
|
||||
|
||||
before { get :index }
|
||||
|
||||
expect_assigns(execution_environments: ExecutionEnvironment.all)
|
||||
expect_status(200)
|
||||
@ -81,7 +86,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([])
|
||||
get :new
|
||||
end
|
||||
@ -96,7 +101,7 @@ describe ExecutionEnvironmentsController do
|
||||
context 'when Docker is available' do
|
||||
let(:docker_images) { [1, 2, 3] }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect(DockerClient).to receive(:check_availability!).at_least(:once)
|
||||
expect(DockerClient).to receive(:image_tags).and_return(docker_images)
|
||||
controller.send(:set_docker_images)
|
||||
@ -108,7 +113,7 @@ describe ExecutionEnvironmentsController do
|
||||
context 'when Docker is unavailable' do
|
||||
let(:error_message) { 'Docker is unavailable' }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect(DockerClient).to receive(:check_availability!).at_least(:once).and_raise(DockerClient::Error.new(error_message))
|
||||
controller.send(:set_docker_images)
|
||||
end
|
||||
@ -123,7 +128,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
describe 'GET #shell' do
|
||||
before(:each) { get :shell, params: { id: execution_environment.id } }
|
||||
before { get :shell, params: {id: execution_environment.id} }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_status(200)
|
||||
@ -131,7 +136,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
describe 'GET #statistics' do
|
||||
before(:each) { get :statistics, params: { id: execution_environment.id } }
|
||||
before { get :statistics, params: {id: execution_environment.id} }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_status(200)
|
||||
@ -139,7 +144,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, params: { id: execution_environment.id } }
|
||||
before { get :show, params: {id: execution_environment.id} }
|
||||
|
||||
expect_assigns(execution_environment: :execution_environment)
|
||||
expect_status(200)
|
||||
@ -148,9 +153,9 @@ describe ExecutionEnvironmentsController do
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid execution environment' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(DockerClient).to receive(:image_tags).at_least(:once).and_return([])
|
||||
put :update, params: { execution_environment: FactoryBot.attributes_for(:ruby), id: execution_environment.id }
|
||||
put :update, params: {execution_environment: FactoryBot.attributes_for(:ruby), id: execution_environment.id}
|
||||
end
|
||||
|
||||
expect_assigns(docker_images: Array)
|
||||
@ -159,7 +164,7 @@ describe ExecutionEnvironmentsController do
|
||||
end
|
||||
|
||||
context 'with an invalid execution environment' do
|
||||
before(:each) { put :update, params: { execution_environment: {name: ''}, id: execution_environment.id } }
|
||||
before { put :update, params: {execution_environment: {name: ''}, id: execution_environment.id} }
|
||||
|
||||
expect_assigns(execution_environment: ExecutionEnvironment)
|
||||
expect_status(200)
|
||||
|
@ -5,12 +5,14 @@ require 'rails_helper'
|
||||
describe ExercisesController do
|
||||
let(:exercise) { FactoryBot.create(:dummy) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'PUT #batch_update' do
|
||||
let(:attributes) { { 'public': 'true'} }
|
||||
let(:perform_request) { proc { put :batch_update, params: { exercises: {0 => attributes.merge(id: exercise.id)} } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:attributes) { {public: 'true'} }
|
||||
let(:perform_request) { proc { put :batch_update, params: {exercises: {0 => attributes.merge(id: exercise.id)}} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
it 'updates the exercises' do
|
||||
expect_any_instance_of(Exercise).to receive(:update).with(attributes)
|
||||
@ -22,10 +24,10 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
describe 'POST #clone' do
|
||||
let(:perform_request) { proc { post :clone, params: { id: exercise.id } } }
|
||||
let(:perform_request) { proc { post :clone, params: {id: exercise.id} } }
|
||||
|
||||
context 'when saving succeeds' do
|
||||
before(:each) { perform_request.call }
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(exercise: Exercise)
|
||||
|
||||
@ -42,7 +44,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'when saving fails' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect_any_instance_of(Exercise).to receive(:save).and_return(false)
|
||||
perform_request.call
|
||||
end
|
||||
@ -57,8 +59,9 @@ describe ExercisesController do
|
||||
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
|
||||
|
||||
context 'with a valid exercise' do
|
||||
let(:perform_request) { proc { post :create, params: { exercise: exercise_attributes } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(exercise: Exercise)
|
||||
|
||||
@ -70,7 +73,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'when including a file' do
|
||||
let(:perform_request) { proc { post :create, params: { exercise: exercise_attributes.merge(files_attributes: files_attributes) } } }
|
||||
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes.merge(files_attributes: files_attributes)} } }
|
||||
|
||||
context 'when specifying the file content within the form' do
|
||||
let(:files_attributes) { {'0' => FactoryBot.build(:file).attributes} }
|
||||
@ -116,7 +119,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'with an invalid exercise' do
|
||||
before(:each) { post :create, params: { exercise: { } } }
|
||||
before { post :create, params: {exercise: {}} }
|
||||
|
||||
expect_assigns(exercise: Exercise)
|
||||
expect_status(200)
|
||||
@ -125,20 +128,20 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) { delete :destroy, params: { id: exercise.id } }
|
||||
before { delete :destroy, params: {id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
|
||||
it 'destroys the exercise' do
|
||||
exercise = FactoryBot.create(:dummy)
|
||||
expect { delete :destroy, params: { id: exercise.id } }.to change(Exercise, :count).by(-1)
|
||||
expect { delete :destroy, params: {id: exercise.id} }.to change(Exercise, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:exercises)
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) { get :edit, params: { id: exercise.id } }
|
||||
before { get :edit, params: {id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
expect_status(200)
|
||||
@ -146,11 +149,12 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
describe 'GET #implement' do
|
||||
let(:perform_request) { proc { get :implement, params: { id: exercise.id } } }
|
||||
let(:perform_request) { proc { get :implement, params: {id: exercise.id} } }
|
||||
|
||||
context 'with an exercise with visible files' do
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
before(:each) { perform_request.call }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
|
||||
@ -174,7 +178,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'with an exercise without visible files' do
|
||||
before(:each) { perform_request.call }
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
expect_flash_message(:alert, :'exercises.implement.no_files')
|
||||
@ -184,8 +188,10 @@ describe ExercisesController do
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:scope) { Pundit.policy_scope!(user, Exercise) }
|
||||
|
||||
before(:all) { FactoryBot.create_pair(:dummy) }
|
||||
before(:each) { get :index }
|
||||
|
||||
before { get :index }
|
||||
|
||||
expect_assigns(exercises: :scope)
|
||||
expect_status(200)
|
||||
@ -193,7 +199,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) { get :new }
|
||||
before { get :new }
|
||||
|
||||
expect_assigns(execution_environments: ExecutionEnvironment.all, exercise: Exercise)
|
||||
expect_assigns(exercise: Exercise)
|
||||
@ -203,7 +209,7 @@ describe ExercisesController do
|
||||
|
||||
describe 'GET #show' do
|
||||
context 'as admin' do
|
||||
before(:each) { get :show, params: { id: exercise.id } }
|
||||
before { get :show, params: {id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
expect_status(200)
|
||||
@ -213,7 +219,7 @@ describe ExercisesController do
|
||||
|
||||
describe 'GET #reload' do
|
||||
context 'as anyone' do
|
||||
before(:each) { get :reload, format: :json, params: { id: exercise.id } }
|
||||
before { get :reload, format: :json, params: {id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
expect_status(200)
|
||||
@ -222,7 +228,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
describe 'GET #statistics' do
|
||||
before(:each) { get :statistics, params: { id: exercise.id } }
|
||||
before { get :statistics, params: {id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: :exercise)
|
||||
expect_status(200)
|
||||
@ -231,23 +237,23 @@ describe ExercisesController do
|
||||
|
||||
describe 'POST #submit' do
|
||||
let(:output) { {} }
|
||||
let(:perform_request) { post :submit, format: :json, params: { id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id} } }
|
||||
let(:perform_request) { post :submit, format: :json, params: {id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id}} }
|
||||
let(:user) { FactoryBot.create(:external_user) }
|
||||
let!(:lti_parameter) { FactoryBot.create(:lti_parameter, external_user: user, exercise: exercise) }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
allow_any_instance_of(Submission).to receive(:normalized_score).and_return(1)
|
||||
expect(controller).to receive(:collect_test_results).and_return([{score: 1, weight: 1}])
|
||||
expect(controller).to receive(:score_submission).and_call_original
|
||||
end
|
||||
|
||||
context 'when LTI outcomes are supported' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:lti_outcome_service?).and_return(true)
|
||||
end
|
||||
|
||||
context 'when the score transmission succeeds' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:send_score).and_return(status: 'success')
|
||||
perform_request
|
||||
end
|
||||
@ -263,7 +269,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'when the score transmission fails' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:send_score).and_return(status: 'unsupported')
|
||||
perform_request
|
||||
end
|
||||
@ -280,7 +286,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'when LTI outcomes are not supported' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:lti_outcome_service?).and_return(false)
|
||||
expect(controller).not_to receive(:send_score)
|
||||
perform_request
|
||||
@ -300,14 +306,15 @@ describe ExercisesController do
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid exercise' do
|
||||
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
|
||||
before(:each) { put :update, params: { exercise: exercise_attributes, id: exercise.id } }
|
||||
|
||||
before { put :update, params: {exercise: exercise_attributes, id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: Exercise)
|
||||
expect_redirect(:exercise)
|
||||
end
|
||||
|
||||
context 'with an invalid exercise' do
|
||||
before(:each) { put :update, params: { exercise: {title: ''}, id: exercise.id } }
|
||||
before { put :update, params: {exercise: {title: ''}, id: exercise.id} }
|
||||
|
||||
expect_assigns(exercise: Exercise)
|
||||
expect_status(200)
|
||||
@ -321,7 +328,7 @@ describe ExercisesController do
|
||||
describe 'POST #export_external_check' do
|
||||
render_views
|
||||
|
||||
let(:post_request) { post :export_external_check, params: { id: exercise.id } }
|
||||
let(:post_request) { post :export_external_check, params: {id: exercise.id} }
|
||||
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
|
||||
let(:external_check_hash) { {message: message, exercise_found: true, update_right: update_right, error: error} }
|
||||
let(:message) { 'message' }
|
||||
@ -509,7 +516,7 @@ describe ExercisesController do
|
||||
end
|
||||
|
||||
context 'when the imported exercise is invalid' do
|
||||
before { allow(ProformaService::Import).to receive(:call) { imported_exercise.tap { |e| e.files = [] }.tap { |e| e.title = nil } } }
|
||||
before { allow(ProformaService::Import).to receive(:call) { imported_exercise.tap {|e| e.files = [] }.tap {|e| e.title = nil } } }
|
||||
|
||||
it 'responds with correct status code' do
|
||||
expect { post_request }.not_to(change { imported_exercise.reload.files.count })
|
||||
|
@ -1,12 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ExternalUsersController do
|
||||
let(:user) { FactoryBot.build(:admin) }
|
||||
let!(:users) { FactoryBot.create_pair(:external_user) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'GET #index' do
|
||||
before(:each) { get :index }
|
||||
before { get :index }
|
||||
|
||||
expect_assigns(users: ExternalUser.all)
|
||||
expect_status(200)
|
||||
@ -14,7 +17,7 @@ describe ExternalUsersController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, params: { id: users.first.id } }
|
||||
before { get :show, params: {id: users.first.id} }
|
||||
|
||||
expect_assigns(user: ExternalUser)
|
||||
expect_status(200)
|
||||
|
@ -1,14 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe FileTypesController do
|
||||
let(:file_type) { FactoryBot.create(:dot_rb) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with a valid file type' do
|
||||
let(:perform_request) { proc { post :create, params: { file_type: FactoryBot.attributes_for(:dot_rb) } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, params: {file_type: FactoryBot.attributes_for(:dot_rb)} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(editor_modes: Array)
|
||||
expect_assigns(file_type: FileType)
|
||||
@ -21,7 +25,7 @@ describe FileTypesController do
|
||||
end
|
||||
|
||||
context 'with an invalid file type' do
|
||||
before(:each) { post :create, params: { file_type: { } } }
|
||||
before { post :create, params: {file_type: {}} }
|
||||
|
||||
expect_assigns(editor_modes: Array)
|
||||
expect_assigns(file_type: FileType)
|
||||
@ -31,20 +35,20 @@ describe FileTypesController do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) { delete :destroy, params: { id: file_type.id } }
|
||||
before { delete :destroy, params: {id: file_type.id} }
|
||||
|
||||
expect_assigns(file_type: FileType)
|
||||
|
||||
it 'destroys the file type' do
|
||||
file_type = FactoryBot.create(:dot_rb)
|
||||
expect { delete :destroy, params: { id: file_type.id } }.to change(FileType, :count).by(-1)
|
||||
expect { delete :destroy, params: {id: file_type.id} }.to change(FileType, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:file_types)
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) { get :edit, params: { id: file_type.id } }
|
||||
before { get :edit, params: {id: file_type.id} }
|
||||
|
||||
expect_assigns(editor_modes: Array)
|
||||
expect_assigns(file_type: FileType)
|
||||
@ -54,7 +58,8 @@ describe FileTypesController do
|
||||
|
||||
describe 'GET #index' do
|
||||
before(:all) { FactoryBot.create_pair(:dot_rb) }
|
||||
before(:each) { get :index }
|
||||
|
||||
before { get :index }
|
||||
|
||||
expect_assigns(file_types: FileType.all)
|
||||
expect_status(200)
|
||||
@ -62,7 +67,7 @@ describe FileTypesController do
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) { get :new }
|
||||
before { get :new }
|
||||
|
||||
expect_assigns(editor_modes: Array)
|
||||
expect_assigns(file_type: FileType)
|
||||
@ -71,7 +76,7 @@ describe FileTypesController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, params: { id: file_type.id } }
|
||||
before { get :show, params: {id: file_type.id} }
|
||||
|
||||
expect_assigns(file_type: :file_type)
|
||||
expect_status(200)
|
||||
@ -80,7 +85,7 @@ describe FileTypesController do
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid file type' do
|
||||
before(:each) { put :update, params: { file_type: FactoryBot.attributes_for(:dot_rb), id: file_type.id } }
|
||||
before { put :update, params: {file_type: FactoryBot.attributes_for(:dot_rb), id: file_type.id} }
|
||||
|
||||
expect_assigns(editor_modes: Array)
|
||||
expect_assigns(file_type: FileType)
|
||||
@ -88,7 +93,7 @@ describe FileTypesController do
|
||||
end
|
||||
|
||||
context 'with an invalid file type' do
|
||||
before(:each) { put :update, params: { file_type: {name: ''}, id: file_type.id } }
|
||||
before { put :update, params: {file_type: {name: ''}, id: file_type.id} }
|
||||
|
||||
expect_assigns(editor_modes: Array)
|
||||
expect_assigns(file_type: FileType)
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe InternalUsersController do
|
||||
@ -7,28 +9,28 @@ describe InternalUsersController do
|
||||
describe 'GET #activate' do
|
||||
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
user.send(:setup_activation)
|
||||
user.save(validate: false)
|
||||
end
|
||||
|
||||
context 'without a valid activation token' do
|
||||
before(:each) { get :activate, params: { id: user.id } }
|
||||
before { get :activate, params: {id: user.id} }
|
||||
|
||||
expect_redirect(:root)
|
||||
end
|
||||
|
||||
context 'with an already activated user' do
|
||||
before(:each) do
|
||||
before do
|
||||
user.activate!
|
||||
get :activate, params: { id: user.id, token: user.activation_token }
|
||||
get :activate, params: {id: user.id, token: user.activation_token}
|
||||
end
|
||||
|
||||
expect_redirect(:root)
|
||||
end
|
||||
|
||||
context 'with valid preconditions' do
|
||||
before(:each) { get :activate, params: { id: user.id, token: user.activation_token } }
|
||||
before { get :activate, params: {id: user.id, token: user.activation_token} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
expect_status(200)
|
||||
@ -40,29 +42,29 @@ describe InternalUsersController do
|
||||
let(:user) { InternalUser.create(FactoryBot.build(:teacher).attributes) }
|
||||
let(:password) { SecureRandom.hex }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
user.send(:setup_activation)
|
||||
user.save(validate: false)
|
||||
expect(user.activation_token).to be_present
|
||||
end
|
||||
|
||||
context 'without a valid activation token' do
|
||||
before(:each) { put :activate, params: { id: user.id } }
|
||||
before { put :activate, params: {id: user.id} }
|
||||
|
||||
expect_redirect(:root)
|
||||
end
|
||||
|
||||
context 'with an already activated user' do
|
||||
before(:each) do
|
||||
before do
|
||||
user.activate!
|
||||
put :activate, params: { id: user.id, internal_user: {activation_token: user.activation_token, password: password, password_confirmation: password} }
|
||||
put :activate, params: {id: user.id, internal_user: {activation_token: user.activation_token, password: password, password_confirmation: password}}
|
||||
end
|
||||
|
||||
expect_redirect(:root)
|
||||
end
|
||||
|
||||
context 'without a password' do
|
||||
before(:each) { put :activate, params: { id: user.id, internal_user: {activation_token: user.activation_token} } }
|
||||
before { put :activate, params: {id: user.id, internal_user: {activation_token: user.activation_token}} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
|
||||
@ -74,7 +76,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
context 'without a valid password confirmation' do
|
||||
before(:each) { put :activate, params: { id: user.id, internal_user: {activation_token: user.activation_token, password: password, password_confirmation: ''} } }
|
||||
before { put :activate, params: {id: user.id, internal_user: {activation_token: user.activation_token, password: password, password_confirmation: ''}} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
|
||||
@ -86,7 +88,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
context 'with valid preconditions' do
|
||||
before(:each) { put :activate, params: { id: user.id, internal_user: {activation_token: user.activation_token, password: password, password_confirmation: password} } }
|
||||
before { put :activate, params: {id: user.id, internal_user: {activation_token: user.activation_token, password: password, password_confirmation: password}} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
|
||||
@ -100,11 +102,12 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
context 'with a valid internal user' do
|
||||
let(:perform_request) { proc { post :create, params: { internal_user: FactoryBot.build(:teacher).attributes } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, params: {internal_user: FactoryBot.build(:teacher).attributes} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
|
||||
@ -129,7 +132,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
context 'with an invalid internal user' do
|
||||
before(:each) { post :create, params: { internal_user: {} } }
|
||||
before { post :create, params: {internal_user: {}} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
expect_status(200)
|
||||
@ -138,24 +141,24 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:current_user).and_return(user)
|
||||
delete :destroy, params: { id: users.first.id }
|
||||
delete :destroy, params: {id: users.first.id}
|
||||
end
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
|
||||
it 'destroys the internal user' do
|
||||
expect { delete :destroy, params: { id: InternalUser.last.id } }.to change(InternalUser, :count).by(-1)
|
||||
expect { delete :destroy, params: {id: InternalUser.last.id} }.to change(InternalUser, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:internal_users)
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:current_user).and_return(user)
|
||||
get :edit, params: { id: users.first.id }
|
||||
get :edit, params: {id: users.first.id}
|
||||
end
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
@ -165,7 +168,7 @@ describe InternalUsersController do
|
||||
|
||||
describe 'GET #forgot_password' do
|
||||
context 'when no user is logged in' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
||||
|
||||
expect(controller).to receive(:current_user).and_return(nil)
|
||||
@ -177,7 +180,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
context 'when a user is already logged in' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
||||
|
||||
expect(controller).to receive(:current_user).and_return(user)
|
||||
@ -191,8 +194,9 @@ describe InternalUsersController do
|
||||
|
||||
describe 'POST #forgot_password' do
|
||||
context 'with an email address' do
|
||||
let(:perform_request) { proc { post :forgot_password, params: { email: user.email } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :forgot_password, params: {email: user.email} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
it 'delivers instructions to reset the password' do
|
||||
expect(InternalUser).to receive(:where).and_return([user])
|
||||
@ -204,7 +208,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
context 'without an email address' do
|
||||
before(:each) { post :forgot_password }
|
||||
before { post :forgot_password }
|
||||
|
||||
expect_status(200)
|
||||
expect_template(:forgot_password)
|
||||
@ -212,7 +216,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:current_user).and_return(user)
|
||||
get :index
|
||||
end
|
||||
@ -223,7 +227,7 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:current_user).and_return(user)
|
||||
get :new
|
||||
end
|
||||
@ -237,15 +241,15 @@ describe InternalUsersController do
|
||||
let(:user) { users.first }
|
||||
|
||||
context 'without a valid password reset token' do
|
||||
before(:each) { get :reset_password, params: { id: user.id } }
|
||||
before { get :reset_password, params: {id: user.id} }
|
||||
|
||||
expect_redirect(:root)
|
||||
end
|
||||
|
||||
context 'with a valid password reset token' do
|
||||
before(:each) do
|
||||
before do
|
||||
user.deliver_reset_password_instructions!
|
||||
get :reset_password, params: { id: user.id, token: user.reset_password_token }
|
||||
get :reset_password, params: {id: user.id, token: user.reset_password_token}
|
||||
end
|
||||
|
||||
expect_assigns(user: :user)
|
||||
@ -256,10 +260,11 @@ describe InternalUsersController do
|
||||
|
||||
describe 'PUT #reset_password' do
|
||||
let(:user) { users.first }
|
||||
before(:each) { user.deliver_reset_password_instructions! }
|
||||
|
||||
before { user.deliver_reset_password_instructions! }
|
||||
|
||||
context 'without a valid password reset token' do
|
||||
before(:each) { put :reset_password, params: { id: user.id } }
|
||||
before { put :reset_password, params: {id: user.id} }
|
||||
|
||||
expect_redirect(:root)
|
||||
end
|
||||
@ -268,8 +273,9 @@ describe InternalUsersController do
|
||||
let(:password) { 'foo' }
|
||||
|
||||
context 'with a matching password confirmation' do
|
||||
let(:perform_request) { proc { put :reset_password, params: { internal_user: {password: password, password_confirmation: password}, id: user.id, token: user.reset_password_token } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { put :reset_password, params: {internal_user: {password: password, password_confirmation: password}, id: user.id, token: user.reset_password_token} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(user: :user)
|
||||
|
||||
@ -281,8 +287,8 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
context 'without a matching password confirmation' do
|
||||
before(:each) do
|
||||
put :reset_password, params: { internal_user: {password: password, password_confirmation: ''}, id: users.first.id, token: user.reset_password_token }
|
||||
before do
|
||||
put :reset_password, params: {internal_user: {password: password, password_confirmation: ''}, id: users.first.id, token: user.reset_password_token}
|
||||
end
|
||||
|
||||
expect_assigns(user: :user)
|
||||
@ -293,9 +299,9 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:current_user).and_return(user)
|
||||
get :show, params: { id: users.first.id }
|
||||
get :show, params: {id: users.first.id}
|
||||
end
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
@ -304,17 +310,17 @@ describe InternalUsersController do
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
context 'with a valid internal user' do
|
||||
before(:each) { put :update, params: { internal_user: FactoryBot.attributes_for(:teacher), id: users.first.id } }
|
||||
before { put :update, params: {internal_user: FactoryBot.attributes_for(:teacher), id: users.first.id} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
expect_redirect { user }
|
||||
end
|
||||
|
||||
context 'with an invalid internal user' do
|
||||
before(:each) { put :update, params: { internal_user: {email: ''}, id: users.first.id } }
|
||||
before { put :update, params: {internal_user: {email: ''}, id: users.first.id} }
|
||||
|
||||
expect_assigns(user: InternalUser)
|
||||
expect_status(200)
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe RequestForCommentsController do
|
||||
@ -24,7 +26,7 @@ describe RequestForCommentsController do
|
||||
rfc_other_study_group.user.update(study_groups: [another_study_group])
|
||||
rfc_other_study_group.submission.update(study_group: another_study_group)
|
||||
|
||||
get :index, params: { "q[submission_study_group_id_in][]": my_study_group.id }
|
||||
get :index, params: {"q[submission_study_group_id_in][]": my_study_group.id}
|
||||
|
||||
expect(assigns(:request_for_comments)).to eq([rfc_within_my_study_group])
|
||||
end
|
||||
@ -47,7 +49,7 @@ describe RequestForCommentsController do
|
||||
describe 'GET #get_rfcs_for_exercise' do
|
||||
before do
|
||||
exercise = FactoryBot.create(:even_odd)
|
||||
get :get_rfcs_for_exercise, params: { exercise_id: exercise.id }
|
||||
get :get_rfcs_for_exercise, params: {exercise_id: exercise.id}
|
||||
end
|
||||
|
||||
expect_status(200)
|
||||
|
@ -11,9 +11,9 @@ describe SessionsController do
|
||||
let(:user_attributes) { FactoryBot.build(:teacher).attributes }
|
||||
|
||||
context 'with valid credentials' do
|
||||
before(:each) do
|
||||
before do
|
||||
user.activate!
|
||||
post :create, params: { email: user.email, password: password, remember_me: 1 }
|
||||
post :create, params: {email: user.email, password: password, remember_me: 1}
|
||||
end
|
||||
|
||||
expect_flash_message(:notice, :'sessions.create.success')
|
||||
@ -21,7 +21,7 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
context 'with invalid credentials' do
|
||||
before(:each) { post :create, params: { email: user.email, password: '', remember_me: 1 } }
|
||||
before { post :create, params: {email: user.email, password: '', remember_me: 1} }
|
||||
|
||||
expect_flash_message(:danger, :'sessions.create.failure')
|
||||
expect_template(:new)
|
||||
@ -32,7 +32,8 @@ describe SessionsController do
|
||||
let(:exercise) { FactoryBot.create(:dummy) }
|
||||
let(:exercise2) { FactoryBot.create(:dummy) }
|
||||
let(:nonce) { SecureRandom.hex }
|
||||
before(:each) { I18n.locale = I18n.default_locale }
|
||||
|
||||
before { I18n.locale = I18n.default_locale }
|
||||
|
||||
context 'without OAuth parameters' do
|
||||
it 'refuses the LTI launch' do
|
||||
@ -44,14 +45,14 @@ describe SessionsController do
|
||||
context 'without a valid consumer key' do
|
||||
it 'refuses the LTI launch' do
|
||||
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.invalid_consumer')).and_call_original
|
||||
post :create_through_lti, params: { oauth_consumer_key: SecureRandom.hex, oauth_signature: SecureRandom.hex }
|
||||
post :create_through_lti, params: {oauth_consumer_key: SecureRandom.hex, oauth_signature: SecureRandom.hex}
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an invalid OAuth signature' do
|
||||
it 'refuses the LTI launch' do
|
||||
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.invalid_signature')).and_call_original
|
||||
post :create_through_lti, params: { oauth_consumer_key: consumer.oauth_key, oauth_signature: SecureRandom.hex }
|
||||
post :create_through_lti, params: {oauth_consumer_key: consumer.oauth_key, oauth_signature: SecureRandom.hex}
|
||||
end
|
||||
end
|
||||
|
||||
@ -60,7 +61,7 @@ describe SessionsController do
|
||||
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true)
|
||||
expect(NonceStore).to receive(:has?).with(nonce).and_return(true)
|
||||
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.used_nonce')).and_call_original
|
||||
post :create_through_lti, params: { oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex }
|
||||
post :create_through_lti, params: {oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex}
|
||||
end
|
||||
end
|
||||
|
||||
@ -68,15 +69,16 @@ describe SessionsController do
|
||||
it 'refuses the LTI launch' do
|
||||
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true)
|
||||
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.invalid_exercise_token')).and_call_original
|
||||
post :create_through_lti, params: { custom_token: '', oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: '123' }
|
||||
post :create_through_lti, params: {custom_token: '', oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: '123'}
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid launch parameters' do
|
||||
let(:locale) { :de }
|
||||
let(:perform_request) { post :create_through_lti, params: { custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id } }
|
||||
let(:perform_request) { post :create_through_lti, params: {custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id} }
|
||||
let(:user) { FactoryBot.create(:external_user, consumer_id: consumer.id) }
|
||||
before(:each) { expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
|
||||
|
||||
before { expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
|
||||
|
||||
it 'assigns the current user' do
|
||||
perform_request
|
||||
@ -96,7 +98,7 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
it 'stores LTI parameters in the session' do
|
||||
#Todo replace session with lti_parameter /should be done already
|
||||
# Todo replace session with lti_parameter /should be done already
|
||||
expect(controller).to receive(:store_lti_session_data)
|
||||
perform_request
|
||||
end
|
||||
@ -109,7 +111,7 @@ describe SessionsController do
|
||||
context 'when LTI outcomes are supported' do
|
||||
let(:message) { I18n.t('sessions.create_through_lti.session_with_outcome', consumer: consumer) }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:lti_outcome_service?).and_return(true)
|
||||
perform_request
|
||||
end
|
||||
@ -120,7 +122,7 @@ describe SessionsController do
|
||||
context 'when LTI outcomes are not supported' do
|
||||
let(:message) { I18n.t('sessions.create_through_lti.session_without_outcome', consumer: consumer) }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect(controller).to receive(:lti_outcome_service?).and_return(false)
|
||||
perform_request
|
||||
end
|
||||
@ -135,7 +137,7 @@ describe SessionsController do
|
||||
|
||||
it 'redirects to recommended exercise if requested token of proxy exercise' do
|
||||
FactoryBot.create(:proxy_exercise, exercises: [exercise])
|
||||
post :create_through_lti, params: { custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id }
|
||||
post :create_through_lti, params: {custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id}
|
||||
expect(controller).to redirect_to(implement_exercise_path(exercise.id))
|
||||
end
|
||||
|
||||
@ -146,7 +148,7 @@ describe SessionsController do
|
||||
exercise.save
|
||||
exercise2.expected_difficulty = 1
|
||||
exercise2.save
|
||||
post :create_through_lti, params: { custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id }
|
||||
post :create_through_lti, params: {custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id}
|
||||
expect(controller).to redirect_to(implement_exercise_path(exercise2.id))
|
||||
end
|
||||
end
|
||||
@ -154,13 +156,14 @@ describe SessionsController do
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let(:user) { double }
|
||||
before(:each) {
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
||||
expect(controller).to receive(:current_user).at_least(:once).and_return(user)
|
||||
}
|
||||
end
|
||||
|
||||
context 'with an internal user' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(user).to receive(:external_user?).and_return(false)
|
||||
allow(user).to receive(:forget_me!)
|
||||
delete :destroy
|
||||
@ -177,13 +180,13 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
context 'with an external user' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(user).to receive(:external_user?).and_return(true)
|
||||
delete :destroy
|
||||
end
|
||||
|
||||
it 'clears the session' do
|
||||
#Todo replace session with lti_parameter /should be done already
|
||||
# Todo replace session with lti_parameter /should be done already
|
||||
expect(controller).to receive(:clear_lti_session_data)
|
||||
delete :destroy
|
||||
end
|
||||
@ -195,19 +198,11 @@ 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(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) }
|
||||
|
||||
before(:each) do
|
||||
#Todo replace session with lti_parameter
|
||||
#Todo create LtiParameter Object
|
||||
# session[:lti_parameters] = {}
|
||||
end
|
||||
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { get :destroy_through_lti, params: {consumer_id: consumer.id, submission_id: submission.id} } }
|
||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) } before { perform_request.call }
|
||||
|
||||
it 'clears the session' do
|
||||
#Todo replace session with lti_parameter /should be done already
|
||||
# Todo replace session with lti_parameter /should be done already
|
||||
expect(controller).to receive(:clear_lti_session_data)
|
||||
perform_request.call
|
||||
end
|
||||
@ -218,7 +213,7 @@ describe SessionsController do
|
||||
|
||||
describe 'GET #new' do
|
||||
context 'when no user is logged in' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
||||
|
||||
expect(controller).to receive(:current_user).and_return(nil)
|
||||
@ -230,7 +225,7 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
context 'when a user is already logged in' do
|
||||
before(:each) do
|
||||
before do
|
||||
allow(controller).to receive(:set_sentry_context).and_return(nil)
|
||||
|
||||
expect(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher))
|
||||
|
@ -1,34 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe StatisticsController do
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
[:show, :graphs].each do |route|
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
%i[show graphs].each do |route|
|
||||
describe "GET ##{route}" do
|
||||
before(:each) { get route }
|
||||
before { get route }
|
||||
|
||||
expect_status(200)
|
||||
expect_template(route)
|
||||
end
|
||||
end
|
||||
|
||||
[:user_activity_history, :rfc_activity_history].each do |route|
|
||||
%i[user_activity_history rfc_activity_history].each do |route|
|
||||
describe "GET ##{route}" do
|
||||
before(:each) { get route }
|
||||
before { get route }
|
||||
|
||||
expect_status(200)
|
||||
expect_template(:activity_history)
|
||||
end
|
||||
end
|
||||
|
||||
[:show, :user_activity, :user_activity_history, :rfc_activity, :rfc_activity_history].each do |route|
|
||||
%i[show user_activity user_activity_history rfc_activity rfc_activity_history].each do |route|
|
||||
describe "GET ##{route}.json" do
|
||||
before(:each) { get route, format: :json }
|
||||
before { get route, format: :json }
|
||||
|
||||
expect_status(200)
|
||||
expect_json
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,19 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SubmissionsController do
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
before { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
before(:each) do
|
||||
before do
|
||||
controller.request.accept = 'application/json'
|
||||
end
|
||||
|
||||
context 'with a valid submission' do
|
||||
let(:exercise) { FactoryBot.create(:hello_world) }
|
||||
let(:perform_request) { proc { post :create, format: :json, params: { submission: FactoryBot.attributes_for(:submission, exercise_id: exercise.id) } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { post :create, format: :json, params: {submission: FactoryBot.attributes_for(:submission, exercise_id: exercise.id)} } }
|
||||
|
||||
before { perform_request.call }
|
||||
|
||||
expect_assigns(submission: Submission)
|
||||
|
||||
@ -26,7 +30,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
context 'with an invalid submission' do
|
||||
before(:each) { post :create, params: { submission: { } } }
|
||||
before { post :create, params: {submission: {}} }
|
||||
|
||||
expect_assigns(submission: Submission)
|
||||
expect_json
|
||||
@ -36,17 +40,18 @@ describe SubmissionsController do
|
||||
|
||||
describe 'GET #download_file' do
|
||||
context 'with an invalid filename' do
|
||||
before(:each) { get :download_file, params: { filename: SecureRandom.hex, id: submission.id } }
|
||||
before { 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 } }
|
||||
|
||||
before { 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' } }
|
||||
let(:file) { submission.collect_files.detect {|file| file.name == 'exercise' && file.file_type.file_extension == '.sql' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
@ -61,10 +66,11 @@ describe SubmissionsController do
|
||||
|
||||
context 'with a valid filename' do
|
||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
|
||||
before(:each) { get :download_file, params: { filename: file.name_with_extension, id: submission.id } }
|
||||
|
||||
before { 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' } }
|
||||
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
@ -77,7 +83,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
context 'for a non-binary file' do
|
||||
let(:file) { submission.collect_files.detect { |file| file.file_type.file_extension == '.js' } }
|
||||
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.js' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
@ -93,7 +99,8 @@ describe SubmissionsController do
|
||||
|
||||
describe 'GET #index' do
|
||||
before(:all) { FactoryBot.create_pair(:submission) }
|
||||
before(:each) { get :index }
|
||||
|
||||
before { get :index }
|
||||
|
||||
expect_assigns(submissions: Submission.all)
|
||||
expect_status(200)
|
||||
@ -104,17 +111,18 @@ describe SubmissionsController do
|
||||
let(:file) { submission.files.first }
|
||||
|
||||
context 'with an invalid filename' do
|
||||
before(:each) { get :render_file, params: { filename: SecureRandom.hex, id: submission.id } }
|
||||
before { 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, params: { filename: file.name_with_extension, id: submission.id } }
|
||||
|
||||
before { 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' } }
|
||||
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.mp4' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
@ -127,7 +135,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
context 'for a non-binary file' do
|
||||
let(:file) { submission.collect_files.detect { |file| file.file_type.file_extension == '.js' } }
|
||||
let(:file) { submission.collect_files.detect {|file| file.file_type.file_extension == '.js' } }
|
||||
|
||||
expect_assigns(file: :file)
|
||||
expect_assigns(submission: :submission)
|
||||
@ -143,24 +151,24 @@ describe SubmissionsController do
|
||||
|
||||
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(:perform_request) { get :run, params: {filename: filename, id: submission.id} }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:write).at_least(3).times
|
||||
end
|
||||
|
||||
context 'when no errors occur during execution' do
|
||||
before(:each) do
|
||||
before do
|
||||
expect_any_instance_of(DockerClient).to receive(:execute_run_command).with(submission, filename).and_return({})
|
||||
perform_request
|
||||
end
|
||||
|
||||
pending("todo")
|
||||
pending('todo')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, params: { id: submission.id } }
|
||||
before { get :show, params: {id: submission.id} }
|
||||
|
||||
expect_assigns(submission: :submission)
|
||||
expect_status(200)
|
||||
@ -172,11 +180,12 @@ describe SubmissionsController do
|
||||
# https://github.com/rails/jbuilder/issues/32
|
||||
render_views
|
||||
|
||||
before(:each) { get :show, params: { id: submission.id }, format: :json }
|
||||
before { get :show, params: {id: submission.id}, format: :json }
|
||||
|
||||
expect_assigns(submission: :submission)
|
||||
expect_status(200)
|
||||
|
||||
[:render, :run, :test].each do |action|
|
||||
%i[render run test].each do |action|
|
||||
describe "##{action}_url" do
|
||||
let(:url) { JSON.parse(response.body).with_indifferent_access.fetch("#{action}_url") }
|
||||
|
||||
@ -186,45 +195,47 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
it 'ends with a placeholder' do
|
||||
expect(url).to end_with(Submission::FILENAME_URL_PLACEHOLDER + '.json')
|
||||
expect(url).to end_with("#{Submission::FILENAME_URL_PLACEHOLDER}.json")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#score_url" do
|
||||
let(:url) { JSON.parse(response.body).with_indifferent_access.fetch("score_url") }
|
||||
describe '#score_url' do
|
||||
let(:url) { JSON.parse(response.body).with_indifferent_access.fetch('score_url') }
|
||||
|
||||
it "corresponds to the score path" do
|
||||
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
|
||||
|
||||
describe 'GET #score' do
|
||||
let(:perform_request) { proc { get :score, params: { id: submission.id } } }
|
||||
before(:each) { perform_request.call }
|
||||
let(:perform_request) { proc { get :score, params: {id: submission.id} } }
|
||||
|
||||
pending("todo: mock puma webserver or encapsulate tubesock call (Tubesock::HijackNotAvailable)")
|
||||
before { perform_request.call }
|
||||
|
||||
pending('todo: mock puma webserver or encapsulate tubesock call (Tubesock::HijackNotAvailable)')
|
||||
end
|
||||
|
||||
describe 'GET #test' do
|
||||
let(:filename) { submission.collect_files.detect(&:teacher_defined_assessment?).name_with_extension }
|
||||
let(:output) { {} }
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
expect_any_instance_of(DockerClient).to receive(:execute_test_command).with(submission, filename)
|
||||
get :test, filename: filename, id: submission.id
|
||||
get :test, params: {filename: filename, id: submission.id}
|
||||
end
|
||||
|
||||
pending("todo")
|
||||
pending('todo')
|
||||
end
|
||||
|
||||
describe '#with_server_sent_events' do
|
||||
let(:response) { ActionDispatch::TestResponse.new }
|
||||
before(:each) { allow(controller).to receive(:response).and_return(response) }
|
||||
|
||||
before { allow(controller).to receive(:response).and_return(response) }
|
||||
|
||||
context 'when no error occurs' do
|
||||
after(:each) { controller.send(:with_server_sent_events) }
|
||||
after { controller.send(:with_server_sent_events) }
|
||||
|
||||
it 'uses server-sent events' do
|
||||
expect(ActionController::Live::SSE).to receive(:new).and_call_original
|
||||
@ -246,7 +257,7 @@ describe SubmissionsController do
|
||||
end
|
||||
|
||||
context 'when an error occurs' do
|
||||
after(:each) { controller.send(:with_server_sent_events) { fail } }
|
||||
after { controller.send(:with_server_sent_events) { raise } }
|
||||
|
||||
it 'uses server-sent events' do
|
||||
expect(ActionController::Live::SSE).to receive(:new).and_call_original
|
||||
|
Reference in New Issue
Block a user