Merge branch 'master' into refactor_proforma_import_export

# Conflicts:
#	spec/controllers/exercises_controller_spec.rb
This commit is contained in:
Karol
2022-01-11 22:20:18 +01:00
122 changed files with 1558 additions and 1424 deletions

View File

@ -3,7 +3,7 @@
require 'rails_helper'
describe Admin::DashboardController do
before { allow(controller).to receive(:current_user).and_return(FactoryBot.build(:admin)) }
before { allow(controller).to receive(:current_user).and_return(build(:admin)) }
describe 'GET #show' do
describe 'with format HTML' do

View File

@ -5,7 +5,7 @@ require 'rails_helper'
describe ApplicationController do
describe '#current_user' do
context 'with an external user' do
let(:external_user) { FactoryBot.create(:external_user) }
let(:external_user) { create(:external_user) }
before { session[:external_user_id] = external_user.id }
@ -15,7 +15,7 @@ describe ApplicationController do
end
context 'without an external user' do
let(:internal_user) { FactoryBot.create(:teacher) }
let(:internal_user) { create(:teacher) }
before { login_user(internal_user) }

View File

@ -3,15 +3,15 @@
require 'rails_helper'
describe CodeOcean::FilesController do
let(:user) { FactoryBot.create(:admin) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
describe 'POST #create' do
let(:submission) { FactoryBot.create(:submission, user: user) }
let(:submission) { 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} } }
let(:perform_request) { proc { post :create, params: {code_ocean_file: build(:file, context: submission).attributes, format: :json} } }
before do
submission.exercise.update(allow_file_creation: true)
@ -41,7 +41,7 @@ describe CodeOcean::FilesController do
end
describe 'DELETE #destroy' do
let(:exercise) { FactoryBot.create(:fibonacci) }
let(:exercise) { create(:fibonacci) }
let(:perform_request) { proc { delete :destroy, params: {id: exercise.files.first.id} } }
before { perform_request.call }
@ -49,7 +49,7 @@ describe CodeOcean::FilesController do
expect_assigns(file: CodeOcean::File)
it 'destroys the file' do
FactoryBot.create(:fibonacci)
create(:fibonacci)
expect { perform_request.call }.to change(CodeOcean::File, :count).by(-1)
end

View File

@ -3,7 +3,7 @@
require 'rails_helper'
describe CodeharborLinksController do
let(:user) { FactoryBot.create(:teacher) }
let(:user) { create(:teacher) }
let(:codeocean_config) { instance_double(CodeOcean::Config) }
let(:codeharbor_config) { {codeharbor: {enabled: true, url: 'http://test.url'}} }
@ -23,7 +23,7 @@ describe CodeharborLinksController do
end
describe 'GET #edit' do
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let(:codeharbor_link) { create(:codeharbor_link, user: user) }
before { get :edit, params: {id: codeharbor_link.id} }
@ -57,7 +57,7 @@ describe CodeharborLinksController do
end
describe 'PUT #update' do
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
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'} }
@ -92,7 +92,7 @@ describe CodeharborLinksController do
end
describe 'DELETE #destroy' do
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
let(:destroy_request) { delete :destroy, params: {id: codeharbor_link.id} }
it 'deletes codeharbor_link' do

View File

@ -3,14 +3,14 @@
require 'rails_helper'
describe ConsumersController do
let(:consumer) { FactoryBot.create(:consumer) }
let(:user) { FactoryBot.create(:admin) }
let(:consumer) { create(:consumer) }
let(:user) { create(:admin) }
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)} } }
let(:perform_request) { proc { post :create, params: {consumer: attributes_for(:consumer)} } }
before { perform_request.call }
@ -38,7 +38,7 @@ describe ConsumersController do
expect_assigns(consumer: Consumer)
it 'destroys the consumer' do
consumer = FactoryBot.create(:consumer)
consumer = create(:consumer)
expect { delete :destroy, params: {id: consumer.id} }.to change(Consumer, :count).by(-1)
end
@ -55,7 +55,7 @@ describe ConsumersController do
describe 'GET #index' do
before do
FactoryBot.create_pair(:consumer)
create_pair(:consumer)
get :index
end
@ -82,7 +82,7 @@ describe ConsumersController do
describe 'PUT #update' do
context 'with a valid consumer' do
before { put :update, params: {consumer: FactoryBot.attributes_for(:consumer), id: consumer.id} }
before { put :update, params: {consumer: attributes_for(:consumer), id: consumer.id} }
expect_assigns(consumer: Consumer)
expect_redirect(:consumer)

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe ErrorTemplateAttributesController do
let!(:error_template_attribute) { FactoryBot.create(:error_template_attribute) }
let(:user) { FactoryBot.create(:admin) }
let!(:error_template_attribute) { create(:error_template_attribute) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
@ -35,7 +35,7 @@ describe ErrorTemplateAttributesController do
end
it 'updates error_template_attribute' do
patch :update, params: {id: error_template_attribute, error_template_attribute: FactoryBot.attributes_for(:error_template_attribute)}
patch :update, params: {id: error_template_attribute, error_template_attribute: attributes_for(:error_template_attribute)}
expect(response).to redirect_to(error_template_attribute_path(assigns(:error_template_attribute)))
end

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe ErrorTemplatesController do
let!(:error_template) { FactoryBot.create(:error_template) }
let(:user) { FactoryBot.create(:admin) }
let!(:error_template) { create(:error_template) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
@ -35,7 +35,7 @@ describe ErrorTemplatesController do
end
it 'updates error_template' do
patch :update, params: {id: error_template, error_template: FactoryBot.attributes_for(:error_template)}
patch :update, params: {id: error_template, error_template: attributes_for(:error_template)}
expect(response).to redirect_to(error_template_path(assigns(:error_template)))
end

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe EventsController do
let(:user) { FactoryBot.create(:admin) }
let(:exercise) { FactoryBot.create(:fibonacci) }
let(:user) { create(:admin) }
let(:exercise) { create(:fibonacci) }
before { allow(controller).to receive(:current_user).and_return(user) }

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe ExecutionEnvironmentsController do
let(:execution_environment) { FactoryBot.create(:ruby) }
let(:user) { FactoryBot.create(:admin) }
let(:execution_environment) { create(:ruby) }
let(:user) { create(:admin) }
before do
allow(controller).to receive(:current_user).and_return(user)
@ -13,7 +13,7 @@ describe ExecutionEnvironmentsController do
describe 'POST #create' do
context 'with a valid execution environment' do
let(:perform_request) { proc { post :create, params: {execution_environment: FactoryBot.build(:ruby, pool_size: 1).attributes} } }
let(:perform_request) { proc { post :create, params: {execution_environment: build(:ruby, pool_size: 1).attributes} } }
before do
allow(Rails.env).to receive(:test?).and_return(false, true)
@ -64,7 +64,7 @@ describe ExecutionEnvironmentsController do
expect_assigns(execution_environment: :execution_environment)
it 'destroys the execution environment' do
execution_environment = FactoryBot.create(:ruby)
execution_environment = create(:ruby)
expect { delete :destroy, params: {id: execution_environment.id} }.to change(ExecutionEnvironment, :count).by(-1)
end
@ -103,7 +103,7 @@ describe ExecutionEnvironmentsController do
describe 'GET #index' do
before do
FactoryBot.create_pair(:ruby)
create_pair(:ruby)
get :index
end
@ -186,7 +186,7 @@ describe ExecutionEnvironmentsController do
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: FactoryBot.attributes_for(:ruby, pool_size: 1), id: execution_environment.id}
put :update, params: {execution_environment: attributes_for(:ruby, pool_size: 1), id: execution_environment.id}
end
expect_assigns(docker_images: Array)
@ -216,8 +216,8 @@ describe ExecutionEnvironmentsController do
end
describe '#sync_all_to_runner_management' do
let(:execution_environments) { %i[ruby java python].map {|environment| FactoryBot.create(environment) } }
let(:outdated_execution_environments) { %i[node_js html].map {|environment| FactoryBot.build_stubbed(environment) } }
let(:execution_environments) { %i[ruby java python].map {|environment| create(environment) } }
let(:outdated_execution_environments) { %i[node_js html].map {|environment| build_stubbed(environment) } }
let(:codeocean_config) { instance_double(CodeOcean::Config) }
let(:runner_management_config) { {runner_management: {enabled: true, strategy: :poseidon}} }

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe ExercisesController do
let(:exercise) { FactoryBot.create(:dummy) }
let(:user) { FactoryBot.create(:admin) }
let(:exercise) { create(:dummy) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
@ -56,7 +56,7 @@ describe ExercisesController do
end
describe 'POST #create' do
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
let(:exercise_attributes) { build(:dummy).attributes }
context 'with a valid exercise' do
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes} } }
@ -76,7 +76,7 @@ describe ExercisesController do
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} }
let(:files_attributes) { {'0' => build(:file).attributes} }
it 'creates the file' do
expect { perform_request.call }.to change(CodeOcean::File, :count)
@ -84,11 +84,11 @@ describe ExercisesController do
end
context 'when uploading a file' do
let(:files_attributes) { {'0' => FactoryBot.build(:file, file_type: file_type).attributes.merge(content: uploaded_file)} }
let(:files_attributes) { {'0' => build(:file, file_type: file_type).attributes.merge(content: uploaded_file)} }
context 'when uploading a binary file' do
let(:file_path) { Rails.root.join('db/seeds/audio_video/devstories.mp4') }
let(:file_type) { FactoryBot.create(:dot_mp4) }
let(:file_type) { create(:dot_mp4) }
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'video/mp4', true) }
it 'creates the file' do
@ -103,7 +103,7 @@ describe ExercisesController do
context 'when uploading a non-binary file' do
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
let(:file_type) { FactoryBot.create(:dot_rb) }
let(:file_type) { create(:dot_rb) }
let(:uploaded_file) { Rack::Test::UploadedFile.new(file_path, 'text/x-ruby', false) }
it 'creates the file' do
@ -133,7 +133,7 @@ describe ExercisesController do
expect_assigns(exercise: :exercise)
it 'destroys the exercise' do
exercise = FactoryBot.create(:dummy)
exercise = create(:dummy)
expect { delete :destroy, params: {id: exercise.id} }.to change(Exercise, :count).by(-1)
end
@ -152,14 +152,14 @@ describe ExercisesController do
let(:perform_request) { proc { get :implement, params: {id: exercise.id} } }
context 'with an exercise with visible files' do
let(:exercise) { FactoryBot.create(:fibonacci) }
let(:exercise) { create(:fibonacci) }
before { perform_request.call }
expect_assigns(exercise: :exercise)
context 'with an existing submission' do
let!(:submission) { FactoryBot.create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
let!(:submission) { create(:submission, exercise_id: exercise.id, user_id: user.id, user_type: user.class.name) }
it "populates the editors with the submission's files' content" do
perform_request.call
@ -190,7 +190,7 @@ describe ExercisesController do
let(:scope) { Pundit.policy_scope!(user, Exercise) }
before do
FactoryBot.create_pair(:dummy)
create_pair(:dummy)
get :index
end
@ -239,7 +239,7 @@ 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(:user) { FactoryBot.create(:external_user) }
let(:user) { create(:external_user) }
let(:scoring_response) do
[{
status: :ok,
@ -260,8 +260,8 @@ describe ExercisesController do
end
before do
FactoryBot.create(:lti_parameter, external_user: user, exercise: exercise)
submission = FactoryBot.build(:submission, exercise: exercise, user: user)
create(:lti_parameter, external_user: user, exercise: exercise)
submission = build(:submission, exercise: exercise, user: user)
allow(submission).to receive(:normalized_score).and_return(1)
allow(submission).to receive(:calculate_score).and_return(scoring_response)
allow(Submission).to receive(:create).and_return(submission)
@ -328,7 +328,7 @@ describe ExercisesController do
describe 'PUT #update' do
context 'with a valid exercise' do
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
let(:exercise_attributes) { build(:dummy).attributes }
before { put :update, params: {exercise: exercise_attributes, id: exercise.id} }
@ -352,7 +352,7 @@ describe ExercisesController do
render_views
let(:post_request) { post :export_external_check, params: {id: exercise.id} }
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
let(:external_check_hash) { {message: message, task_found: true, update_right: update_right, error: error} }
let(:message) { 'message' }
let(:update_right) { true }
@ -405,7 +405,7 @@ describe ExercisesController do
describe '#export_external_confirm' do
render_views
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
let(:post_request) { post :export_external_confirm, params: {id: exercise.id, codeharbor_link: codeharbor_link.id} }
let(:error) { nil }
let(:zip) { 'zip' }
@ -440,8 +440,8 @@ describe ExercisesController do
end
describe '#import_uuid_check' do
let(:exercise) { FactoryBot.create(:dummy, uuid: SecureRandom.uuid) }
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let(:exercise) { create(:dummy, uuid: SecureRandom.uuid) }
let!(:codeharbor_link) { create(:codeharbor_link, user: user) }
let(:uuid) { exercise.reload.uuid }
let(:post_request) { post :import_uuid_check, params: {uuid: uuid} }
let(:headers) { {'Authorization' => "Bearer #{codeharbor_link.api_key}"} }
@ -466,7 +466,7 @@ describe ExercisesController do
end
context 'when the user cannot update the exercise' do
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, api_key: 'anotherkey') }
let(:codeharbor_link) { create(:codeharbor_link, api_key: 'anotherkey') }
it 'renders correct response' do
post_request
@ -490,8 +490,8 @@ describe ExercisesController do
end
describe 'POST #import_exercise' do
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let!(:imported_exercise) { FactoryBot.create(:fibonacci) }
let(:codeharbor_link) { create(:codeharbor_link, user: user) }
let!(:imported_exercise) { create(:fibonacci) }
let(:post_request) { post :import_exercise, body: zip_file_content }
let(:zip_file_content) { 'zipped task xml' }
let(:headers) { {'Authorization' => "Bearer #{codeharbor_link.api_key}"} }

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe ExternalUsersController do
let(:user) { FactoryBot.build(:admin) }
let!(:users) { FactoryBot.create_pair(:external_user) }
let(:user) { build(:admin) }
let!(:users) { create_pair(:external_user) }
before { allow(controller).to receive(:current_user).and_return(user) }

View File

@ -3,14 +3,14 @@
require 'rails_helper'
describe FileTypesController do
let(:file_type) { FactoryBot.create(:dot_rb) }
let(:user) { FactoryBot.create(:admin) }
let(:file_type) { create(:dot_rb) }
let(:user) { create(:admin) }
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)} } }
let(:perform_request) { proc { post :create, params: {file_type: attributes_for(:dot_rb)} } }
before { perform_request.call }
@ -40,7 +40,7 @@ describe FileTypesController do
expect_assigns(file_type: FileType)
it 'destroys the file type' do
file_type = FactoryBot.create(:dot_rb)
file_type = create(:dot_rb)
expect { delete :destroy, params: {id: file_type.id} }.to change(FileType, :count).by(-1)
end
@ -58,7 +58,7 @@ describe FileTypesController do
describe 'GET #index' do
before do
FactoryBot.create_pair(:dot_rb)
create_pair(:dot_rb)
get :index
end
@ -86,7 +86,7 @@ describe FileTypesController do
describe 'PUT #update' do
context 'with a valid file type' do
before { put :update, params: {file_type: FactoryBot.attributes_for(:dot_rb), id: file_type.id} }
before { put :update, params: {file_type: attributes_for(:dot_rb), id: file_type.id} }
expect_assigns(editor_modes: Array)
expect_assigns(file_type: FileType)

View File

@ -3,11 +3,11 @@
require 'rails_helper'
describe InternalUsersController do
let(:user) { FactoryBot.build(:admin) }
let!(:users) { FactoryBot.create_pair(:teacher) }
let(:user) { build(:admin) }
let!(:users) { create_pair(:teacher) }
describe 'GET #activate' do
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
let(:user) { InternalUser.create(attributes_for(:teacher)) }
before do
user.send(:setup_activation)
@ -39,7 +39,7 @@ describe InternalUsersController do
end
describe 'PUT #activate' do
let(:user) { InternalUser.create(FactoryBot.build(:teacher).attributes) }
let(:user) { InternalUser.create(build(:teacher).attributes) }
let(:password) { SecureRandom.hex }
before do
@ -108,7 +108,7 @@ describe InternalUsersController do
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} } }
let(:perform_request) { proc { post :create, params: {internal_user: build(:teacher).attributes} } }
before { perform_request.call }
@ -316,7 +316,7 @@ describe InternalUsersController do
before { allow(controller).to receive(:current_user).and_return(user) }
context 'with a valid internal user' do
before { put :update, params: {internal_user: FactoryBot.attributes_for(:teacher), id: users.first.id} }
before { put :update, params: {internal_user: attributes_for(:teacher), id: users.first.id} }
expect_assigns(user: InternalUser)
expect_redirect { user }

View File

@ -3,7 +3,7 @@
require 'rails_helper'
describe RequestForCommentsController do
let(:user) { FactoryBot.create(:admin) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
@ -16,13 +16,13 @@ describe RequestForCommentsController do
end
it 'shows only rfc`s belonging to selected study group' do
my_study_group = FactoryBot.create(:study_group)
rfc_within_my_study_group = FactoryBot.create(:rfc, user: user)
my_study_group = create(:study_group)
rfc_within_my_study_group = create(:rfc, user: user)
user.update(study_groups: [my_study_group])
rfc_within_my_study_group.submission.update(study_group: my_study_group)
another_study_group = FactoryBot.create(:study_group)
rfc_other_study_group = FactoryBot.create(:rfc)
another_study_group = create(:study_group)
rfc_other_study_group = create(:rfc)
rfc_other_study_group.user.update(study_groups: [another_study_group])
rfc_other_study_group.submission.update(study_group: another_study_group)
@ -48,7 +48,7 @@ describe RequestForCommentsController do
describe 'GET #rfcs_for_exercise' do
before do
exercise = FactoryBot.create(:even_odd)
exercise = create(:even_odd)
get :rfcs_for_exercise, params: {exercise_id: exercise.id}
end

View File

@ -3,12 +3,12 @@
require 'rails_helper'
describe SessionsController do
let(:consumer) { FactoryBot.create(:consumer) }
let(:consumer) { create(:consumer) }
describe 'POST #create' do
let(:password) { FactoryBot.attributes_for(:teacher)[:password] }
let(:password) { attributes_for(:teacher)[:password] }
let(:user) { InternalUser.create(user_attributes.merge(password: password)) }
let(:user_attributes) { FactoryBot.build(:teacher).attributes }
let(:user_attributes) { build(:teacher).attributes }
context 'with valid credentials' do
before do
@ -29,8 +29,8 @@ describe SessionsController do
end
describe 'POST #create_through_lti' do
let(:exercise) { FactoryBot.create(:dummy) }
let(:exercise2) { FactoryBot.create(:dummy) }
let(:exercise) { create(:dummy) }
let(:exercise2) { create(:dummy) }
let(:nonce) { SecureRandom.hex }
context 'without OAuth parameters' do
@ -74,7 +74,7 @@ describe SessionsController do
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(:user) { FactoryBot.create(:external_user, consumer_id: consumer.id) }
let(:user) { create(:external_user, consumer_id: consumer.id) }
before { allow_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
@ -139,14 +139,14 @@ describe SessionsController do
end
it 'redirects to recommended exercise if requested token of proxy exercise' do
FactoryBot.create(:proxy_exercise, exercises: [exercise])
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}
expect(controller).to redirect_to(implement_exercise_path(exercise.id))
end
it 'recommends only exercises who are 1 degree more complicated than what user has seen' do
# dummy user has no exercises finished, therefore his highest difficulty is 0
FactoryBot.create(:proxy_exercise, exercises: [exercise, exercise2])
create(:proxy_exercise, exercises: [exercise, exercise2])
exercise.expected_difficulty = 3
exercise.save
exercise2.expected_difficulty = 1
@ -202,7 +202,7 @@ describe SessionsController do
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)) }
let(:submission) { create(:submission, exercise: create(:dummy)) }
before do
# Todo replace session with lti_parameter
@ -238,7 +238,7 @@ describe SessionsController do
before do
allow(controller).to receive(:set_sentry_context).and_return(nil)
allow(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher))
allow(controller).to receive(:current_user).and_return(build(:teacher))
get :new
end

View File

@ -3,7 +3,7 @@
require 'rails_helper'
describe StatisticsController do
let(:user) { FactoryBot.create(:admin) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }

View File

@ -3,8 +3,8 @@
require 'rails_helper'
describe SubmissionsController do
let(:submission) { FactoryBot.create(:submission) }
let(:user) { FactoryBot.create(:admin) }
let(:submission) { create(:submission) }
let(:user) { create(:admin) }
before { allow(controller).to receive(:current_user).and_return(user) }
@ -14,8 +14,8 @@ describe SubmissionsController do
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)} } }
let(:exercise) { create(:hello_world) }
let(:perform_request) { proc { post :create, format: :json, params: {submission: attributes_for(:submission, exercise_id: exercise.id)} } }
before { perform_request.call }
@ -46,7 +46,7 @@ describe SubmissionsController do
end
context 'with a valid binary filename' do
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:sql_select)) }
let(:submission) { create(:submission, exercise: create(:sql_select)) }
before { get :download_file, params: {filename: file.name_with_extension, id: submission.id} }
@ -65,7 +65,7 @@ describe SubmissionsController do
end
context 'with a valid filename' do
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
let(:submission) { create(:submission, exercise: create(:audio_video)) }
before { get :download_file, params: {filename: file.name_with_extension, id: submission.id} }
@ -99,7 +99,7 @@ describe SubmissionsController do
describe 'GET #index' do
before do
FactoryBot.create_pair(:submission)
create_pair(:submission)
get :index
end
@ -118,7 +118,7 @@ describe SubmissionsController do
end
context 'with a valid filename' do
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:audio_video)) }
let(:submission) { create(:submission, exercise: create(:audio_video)) }
before { get :render_file, params: {filename: file.name_with_extension, id: submission.id} }