Update bundle (with newest rubocop version) and fix offenses
This commit is contained in:
@ -8,11 +8,11 @@ end
|
||||
|
||||
describe FileParameters do
|
||||
let(:controller) { Controller.new }
|
||||
let(:hello_world) { FactoryBot.create(:hello_world) }
|
||||
let(:hello_world) { create(:hello_world) }
|
||||
|
||||
describe '#reject_illegal_file_attributes!' do
|
||||
def file_accepted?(file)
|
||||
files = [[0, FactoryBot.attributes_for(:file, context: hello_world, file_id: file.id)]]
|
||||
files = [[0, attributes_for(:file, context: hello_world, file_id: file.id)]]
|
||||
filtered_files = controller.send(:reject_illegal_file_attributes, hello_world, files)
|
||||
files.eql?(filtered_files)
|
||||
end
|
||||
@ -24,31 +24,31 @@ describe FileParameters do
|
||||
end
|
||||
|
||||
it 'new file' do
|
||||
submission = FactoryBot.create(:submission, exercise: hello_world, id: 1337)
|
||||
new_file = FactoryBot.create(:file, context: submission)
|
||||
submission = create(:submission, exercise: hello_world, id: 1337)
|
||||
new_file = create(:file, context: submission)
|
||||
expect(file_accepted?(new_file)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'rejects' do
|
||||
it 'file of different exercise' do
|
||||
fibonacci = FactoryBot.create(:fibonacci, allow_file_creation: true)
|
||||
other_exercises_file = FactoryBot.create(:file, context: fibonacci)
|
||||
fibonacci = create(:fibonacci, allow_file_creation: true)
|
||||
other_exercises_file = create(:file, context: fibonacci)
|
||||
expect(file_accepted?(other_exercises_file)).to be false
|
||||
end
|
||||
|
||||
it 'hidden file' do
|
||||
hidden_file = FactoryBot.create(:file, context: hello_world, hidden: true)
|
||||
hidden_file = create(:file, context: hello_world, hidden: true)
|
||||
expect(file_accepted?(hidden_file)).to be false
|
||||
end
|
||||
|
||||
it 'read only file' do
|
||||
read_only_file = FactoryBot.create(:file, context: hello_world, read_only: true)
|
||||
read_only_file = create(:file, context: hello_world, read_only: true)
|
||||
expect(file_accepted?(read_only_file)).to be false
|
||||
end
|
||||
|
||||
it 'non existent file' do
|
||||
non_existent_file = FactoryBot.build(:file, context: hello_world, id: 42)
|
||||
non_existent_file = build(:file, context: hello_world, id: 42)
|
||||
expect(file_accepted?(non_existent_file)).to be false
|
||||
end
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ describe Lti do
|
||||
describe '#build_tool_provider' do
|
||||
it 'instantiates a tool provider' do
|
||||
expect(IMS::LTI::ToolProvider).to receive(:new)
|
||||
controller.send(:build_tool_provider, consumer: FactoryBot.build(:consumer), parameters: {})
|
||||
controller.send(:build_tool_provider, consumer: build(:consumer), parameters: {})
|
||||
end
|
||||
end
|
||||
|
||||
@ -101,12 +101,12 @@ describe Lti do
|
||||
end
|
||||
|
||||
describe '#send_score' do
|
||||
let(:consumer) { FactoryBot.create(:consumer) }
|
||||
let(:consumer) { create(:consumer) }
|
||||
let(:score) { 0.5 }
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:submission) { create(:submission) }
|
||||
|
||||
before do
|
||||
FactoryBot.create(:lti_parameter, consumers_id: consumer.id, external_users_id: submission.user_id, exercises_id: submission.exercise_id)
|
||||
create(:lti_parameter, consumers_id: consumer.id, external_users_id: submission.user_id, exercises_id: submission.exercise_id)
|
||||
end
|
||||
|
||||
context 'with an invalid score' do
|
||||
@ -168,18 +168,18 @@ describe Lti do
|
||||
let(:parameters) { ActionController::Parameters.new({}) }
|
||||
|
||||
it 'stores data in the session' do
|
||||
controller.instance_variable_set(:@current_user, FactoryBot.create(:external_user))
|
||||
controller.instance_variable_set(:@exercise, FactoryBot.create(:fibonacci))
|
||||
controller.instance_variable_set(:@current_user, create(:external_user))
|
||||
controller.instance_variable_set(:@exercise, create(:fibonacci))
|
||||
expect(controller.session).to receive(:[]=).with(:external_user_id, anything)
|
||||
expect(controller.session).to receive(:[]=).with(:lti_parameters_id, anything)
|
||||
controller.send(:store_lti_session_data, consumer: FactoryBot.build(:consumer), parameters: parameters)
|
||||
controller.send(:store_lti_session_data, consumer: build(:consumer), parameters: parameters)
|
||||
end
|
||||
|
||||
it 'creates an LtiParameter Object' do
|
||||
before_count = LtiParameter.count
|
||||
controller.instance_variable_set(:@current_user, FactoryBot.create(:external_user))
|
||||
controller.instance_variable_set(:@exercise, FactoryBot.create(:fibonacci))
|
||||
controller.send(:store_lti_session_data, consumer: FactoryBot.build(:consumer), parameters: parameters)
|
||||
controller.instance_variable_set(:@current_user, create(:external_user))
|
||||
controller.instance_variable_set(:@exercise, create(:fibonacci))
|
||||
controller.send(:store_lti_session_data, consumer: build(:consumer), parameters: parameters)
|
||||
expect(LtiParameter.count).to eq(before_count + 1)
|
||||
end
|
||||
end
|
||||
|
@ -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
|
||||
|
@ -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) }
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) }
|
||||
|
||||
|
@ -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}} }
|
||||
|
@ -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, exercise_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}"} }
|
||||
|
@ -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) }
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) }
|
||||
|
||||
|
@ -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} }
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Authentication' do
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
let(:password) { FactoryBot.attributes_for(:admin)[:password] }
|
||||
let(:user) { create(:admin) }
|
||||
let(:password) { attributes_for(:admin)[:password] }
|
||||
|
||||
context 'when signed out' do
|
||||
before { visit(root_path) }
|
||||
|
@ -6,7 +6,7 @@ describe 'Authorization' do
|
||||
before { allow(Runner.strategy_class).to receive(:available_images).and_return([]) }
|
||||
|
||||
context 'when being an admin' do
|
||||
let(:user) { FactoryBot.create(:admin) }
|
||||
let(:user) { create(:admin) }
|
||||
|
||||
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||
|
||||
@ -16,7 +16,7 @@ describe 'Authorization' do
|
||||
end
|
||||
|
||||
context 'with being an external user' do
|
||||
let(:user) { FactoryBot.create(:external_user) }
|
||||
let(:user) { create(:external_user) }
|
||||
|
||||
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||
|
||||
@ -26,7 +26,7 @@ describe 'Authorization' do
|
||||
end
|
||||
|
||||
context 'with being a teacher' do
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:user) { create(:teacher) }
|
||||
|
||||
before { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Editor', js: true do
|
||||
let(:exercise) { FactoryBot.create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
||||
let(:exercise) { create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
||||
let(:scoring_response) do
|
||||
[{
|
||||
status: :ok,
|
||||
@ -22,12 +22,12 @@ describe 'Editor', js: true do
|
||||
weight: 2.0,
|
||||
}]
|
||||
end
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:user) { create(:teacher) }
|
||||
|
||||
before do
|
||||
visit(sign_in_path)
|
||||
fill_in('email', with: user.email)
|
||||
fill_in('password', with: FactoryBot.attributes_for(:teacher)[:password])
|
||||
fill_in('password', with: attributes_for(:teacher)[:password])
|
||||
click_button(I18n.t('sessions.new.link'))
|
||||
allow_any_instance_of(LtiHelper).to receive(:lti_outcome_service?).and_return(true)
|
||||
visit(implement_exercise_path(exercise))
|
||||
@ -94,7 +94,7 @@ describe 'Editor', js: true do
|
||||
end
|
||||
|
||||
it 'contains a button for submitting the exercise' do
|
||||
submission = FactoryBot.build(:submission, user: user, exercise: exercise)
|
||||
submission = build(:submission, user: user, exercise: exercise)
|
||||
allow(submission).to receive(:calculate_score).and_return(scoring_response)
|
||||
allow(Submission).to receive(:find).and_return(submission)
|
||||
click_button(I18n.t('exercises.editor.score'))
|
||||
|
@ -26,7 +26,7 @@ describe Prometheus::Controller do
|
||||
|
||||
describe 'instance count' do
|
||||
it 'initializes the metrics with the current database entries' do
|
||||
FactoryBot.create_list(:proxy_exercise, 3)
|
||||
create_list(:proxy_exercise, 3)
|
||||
described_class.register_metrics
|
||||
stub_metrics
|
||||
described_class.initialize_instance_count
|
||||
@ -35,25 +35,25 @@ describe Prometheus::Controller do
|
||||
|
||||
it 'gets notified when an object is created' do
|
||||
allow(described_class).to receive(:create_notification)
|
||||
proxy_exercise = FactoryBot.create(:proxy_exercise)
|
||||
proxy_exercise = create(:proxy_exercise)
|
||||
expect(described_class).to have_received(:create_notification).with(proxy_exercise).once
|
||||
end
|
||||
|
||||
it 'gets notified when an object is destroyed' do
|
||||
allow(described_class).to receive(:destroy_notification)
|
||||
proxy_exercise = FactoryBot.create(:proxy_exercise).destroy
|
||||
proxy_exercise = create(:proxy_exercise).destroy
|
||||
expect(described_class).to have_received(:destroy_notification).with(proxy_exercise).once
|
||||
end
|
||||
|
||||
it 'increments gauge when creating a new instance' do
|
||||
FactoryBot.create(:proxy_exercise)
|
||||
create(:proxy_exercise)
|
||||
expect(described_class.instance_variable_get(:@instance_count)).to(
|
||||
have_received(:increment).with(class: ProxyExercise.name).once
|
||||
)
|
||||
end
|
||||
|
||||
it 'decrements gauge when deleting an object' do
|
||||
FactoryBot.create(:proxy_exercise).destroy
|
||||
create(:proxy_exercise).destroy
|
||||
expect(described_class.instance_variable_get(:@instance_count)).to(
|
||||
have_received(:decrement).with(class: ProxyExercise.name).once
|
||||
)
|
||||
@ -63,7 +63,7 @@ describe Prometheus::Controller do
|
||||
describe 'rfc count' do
|
||||
context 'when initializing an rfc' do
|
||||
it 'updates rfc count when creating an ongoing rfc' do
|
||||
FactoryBot.create(:rfc)
|
||||
create(:rfc)
|
||||
expect(described_class.instance_variable_get(:@rfc_count)).to(
|
||||
have_received(:increment).with(state: RequestForComment::ONGOING).once
|
||||
)
|
||||
@ -71,7 +71,7 @@ describe Prometheus::Controller do
|
||||
end
|
||||
|
||||
context 'when changing the state of an rfc' do
|
||||
let(:rfc) { FactoryBot.create(:rfc) }
|
||||
let(:rfc) { create(:rfc) }
|
||||
|
||||
it 'updates rfc count when soft-solving an rfc' do
|
||||
rfc.full_score_reached = true
|
||||
@ -90,12 +90,12 @@ describe Prometheus::Controller do
|
||||
|
||||
context 'when commenting an rfc' do
|
||||
it 'updates comment metric when commenting an rfc' do
|
||||
FactoryBot.create(:rfc_with_comment)
|
||||
create(:rfc_with_comment)
|
||||
expect(described_class.instance_variable_get(:@rfc_commented_count)).to have_received(:increment).once
|
||||
end
|
||||
|
||||
it 'does not update comment metric when commenting an rfc that already has a comment' do
|
||||
rfc = FactoryBot.create(:rfc_with_comment)
|
||||
rfc = create(:rfc_with_comment)
|
||||
expect(described_class.instance_variable_get(:@rfc_commented_count)).to have_received(:increment).once
|
||||
|
||||
Comment.create(file: rfc.file, user: rfc.user, text: "comment a for rfc #{rfc.question}")
|
||||
|
@ -3,21 +3,21 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Request_for_Comments' do
|
||||
let(:exercise) { FactoryBot.create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:exercise) { create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
|
||||
let(:user) { create(:teacher) }
|
||||
|
||||
before do
|
||||
visit(sign_in_path)
|
||||
fill_in('email', with: user.email)
|
||||
fill_in('password', with: FactoryBot.attributes_for(:teacher)[:password])
|
||||
fill_in('password', with: attributes_for(:teacher)[:password])
|
||||
click_button(I18n.t('sessions.new.link'))
|
||||
end
|
||||
|
||||
it 'does not contain rfcs for unpublished exercises' do
|
||||
unpublished_rfc = FactoryBot.create(:rfc)
|
||||
unpublished_rfc = create(:rfc)
|
||||
unpublished_rfc.exercise.update(title: 'Unpublished Exercise')
|
||||
unpublished_rfc.exercise.update(unpublished: true)
|
||||
rfc = FactoryBot.create(:rfc)
|
||||
rfc = create(:rfc)
|
||||
rfc.exercise.update(title: 'Normal Exercise')
|
||||
rfc.exercise.update(unpublished: false)
|
||||
|
||||
|
@ -11,7 +11,7 @@ describe Admin::DashboardHelper do
|
||||
|
||||
describe '#docker_data' do
|
||||
before do
|
||||
FactoryBot.create(:ruby)
|
||||
create(:ruby)
|
||||
dcp = instance_double 'docker_container_pool'
|
||||
allow(Runner).to receive(:strategy_class).and_return dcp
|
||||
allow(dcp).to receive(:pool_size).and_return({})
|
||||
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
|
||||
describe ExerciseHelper do
|
||||
describe '#embedding_parameters' do
|
||||
let(:exercise) { FactoryBot.build(:dummy) }
|
||||
let(:exercise) { build(:dummy) }
|
||||
|
||||
it 'contains the locale' do
|
||||
expect(embedding_parameters(exercise)).to start_with("locale=#{I18n.locale}")
|
||||
|
@ -3,7 +3,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Assessor do
|
||||
let(:assessor) { described_class.new(execution_environment: FactoryBot.build(:ruby)) }
|
||||
let(:assessor) { described_class.new(execution_environment: build(:ruby)) }
|
||||
|
||||
describe '#assess' do
|
||||
let(:assess) { assessor.assess(stdout: stdout) }
|
||||
@ -55,7 +55,7 @@ describe Assessor do
|
||||
|
||||
context 'with an execution environment without a testing framework adapter' do
|
||||
it 'raises an error' do
|
||||
expect { described_class.new(execution_environment: FactoryBot.build(:ruby, testing_framework: nil)) }.to raise_error(Assessor::Error)
|
||||
expect { described_class.new(execution_environment: build(:ruby, testing_framework: nil)) }.to raise_error(Assessor::Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,14 +7,14 @@ WORKSPACE_PATH = Rails.root.join('tmp', 'files', Rails.env, 'code_ocean_test')
|
||||
|
||||
describe DockerClient do
|
||||
let(:command) { 'whoami' }
|
||||
let(:docker_client) { described_class.new(execution_environment: FactoryBot.build(:java), user: FactoryBot.build(:admin)) }
|
||||
let(:execution_environment) { FactoryBot.build(:java) }
|
||||
let(:docker_client) { described_class.new(execution_environment: build(:java), user: build(:admin)) }
|
||||
let(:execution_environment) { build(:java) }
|
||||
let(:image) { double }
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:submission) { create(:submission) }
|
||||
let(:workspace_path) { WORKSPACE_PATH }
|
||||
|
||||
before do
|
||||
docker_image = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex, 'RepoTags' => [FactoryBot.attributes_for(:java)[:docker_image]])
|
||||
docker_image = Docker::Image.new(Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex, 'RepoTags' => [attributes_for(:java)[:docker_image]])
|
||||
allow(described_class).to receive(:find_image_by_tag).and_return(docker_image)
|
||||
described_class.initialize_environment
|
||||
allow(described_class).to receive(:container_creation_options).and_wrap_original do |original_method, *args, &block|
|
||||
@ -177,7 +177,7 @@ describe DockerClient do
|
||||
|
||||
describe '#create_workspace_file' do
|
||||
let(:container) { Docker::Container.send(:new, Docker::Connection.new('http://example.org', {}), 'id' => SecureRandom.hex) }
|
||||
let(:file) { FactoryBot.build(:file, content: 'puts 42') }
|
||||
let(:file) { build(:file, content: 'puts 42') }
|
||||
let(:file_path) { File.join(workspace_path, file.name_with_extension) }
|
||||
|
||||
after { File.delete(file_path) }
|
||||
|
@ -10,7 +10,7 @@ describe FileTree do
|
||||
|
||||
context 'with a media file' do
|
||||
context 'with an audio file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp3)) }
|
||||
let(:file) { build(:file, file_type: build(:dot_mp3)) }
|
||||
|
||||
it 'is an audio file icon' do
|
||||
expect(file_icon).to include('fa-file-audio-o')
|
||||
@ -18,7 +18,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
context 'with an image file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_jpg)) }
|
||||
let(:file) { build(:file, file_type: build(:dot_jpg)) }
|
||||
|
||||
it 'is an image file icon' do
|
||||
expect(file_icon).to include('fa-file-image-o')
|
||||
@ -26,7 +26,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
context 'with a video file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_mp4)) }
|
||||
let(:file) { build(:file, file_type: build(:dot_mp4)) }
|
||||
|
||||
it 'is a video file icon' do
|
||||
expect(file_icon).to include('fa-file-video-o')
|
||||
@ -36,7 +36,7 @@ describe FileTree do
|
||||
|
||||
context 'with other files' do
|
||||
context 'with a read-only file' do
|
||||
let(:file) { FactoryBot.build(:file, read_only: true) }
|
||||
let(:file) { build(:file, read_only: true) }
|
||||
|
||||
it 'is a lock icon' do
|
||||
expect(file_icon).to include('fa-lock')
|
||||
@ -44,7 +44,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
context 'with an executable file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_py)) }
|
||||
let(:file) { build(:file, file_type: build(:dot_py)) }
|
||||
|
||||
it 'is a code file icon' do
|
||||
expect(file_icon).to include('fa-file-code-o')
|
||||
@ -52,7 +52,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
context 'with a renderable file' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_svg)) }
|
||||
let(:file) { build(:file, file_type: build(:dot_svg)) }
|
||||
|
||||
it 'is a text file icon' do
|
||||
expect(file_icon).to include('fa-file-text-o')
|
||||
@ -60,7 +60,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
context 'with all other files' do
|
||||
let(:file) { FactoryBot.build(:file, file_type: FactoryBot.build(:dot_md)) }
|
||||
let(:file) { build(:file, file_type: build(:dot_md)) }
|
||||
|
||||
it 'is a generic file icon' do
|
||||
expect(file_icon).to include('fa-file-o')
|
||||
@ -77,7 +77,7 @@ describe FileTree do
|
||||
|
||||
describe '#initialize' do
|
||||
let(:file_tree) { described_class.new(files) }
|
||||
let(:files) { FactoryBot.build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||
|
||||
it 'creates a root node' do
|
||||
# Instead of checking #initialize on the parent, we validate #set_as_root!
|
||||
@ -95,7 +95,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
describe '#map_to_js_tree' do
|
||||
let(:file) { FactoryBot.build(:file) }
|
||||
let(:file) { build(:file) }
|
||||
let(:js_tree) { file_tree.send(:map_to_js_tree, node) }
|
||||
let!(:leaf) { root.add(Tree::TreeNode.new('', file)) }
|
||||
let(:root) { Tree::TreeNode.new('', file) }
|
||||
@ -186,7 +186,7 @@ describe FileTree do
|
||||
end
|
||||
|
||||
context 'with files' do
|
||||
let(:files) { FactoryBot.build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||
let(:file_tree) { described_class.new(files) }
|
||||
let(:js_tree) { file_tree.to_js_tree }
|
||||
|
||||
|
@ -4,8 +4,8 @@ require 'rails_helper'
|
||||
require 'pathname'
|
||||
|
||||
describe Runner::Strategy::DockerContainerPool do
|
||||
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
|
||||
let(:execution_environment) { FactoryBot.create :ruby }
|
||||
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||
let(:execution_environment) { create :ruby }
|
||||
let(:container_pool) { described_class.new(runner_id, execution_environment) }
|
||||
let(:docker_container_pool_url) { 'http://localhost:1234' }
|
||||
let(:config) { {url: docker_container_pool_url, unused_runner_expiration_time: 180} }
|
||||
@ -112,22 +112,20 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
|
||||
context 'when receiving a normal file' do
|
||||
let(:file_content) { 'print("Hello World!")' }
|
||||
let(:files) { [FactoryBot.build(:file, content: file_content)] }
|
||||
let(:files) { [build(:file, content: file_content)] }
|
||||
|
||||
it 'writes the file to disk' do
|
||||
file = instance_double(File)
|
||||
allow(File).to receive(:open).and_yield(file)
|
||||
expect(file).to receive(:write).with(file_content)
|
||||
expect(File).to receive(:write).with(local_path.join(files.first.filepath), file_content)
|
||||
container_pool.copy_files(files)
|
||||
end
|
||||
|
||||
it 'creates the file inside the workspace' do
|
||||
expect(File).to receive(:open).with(local_path.join(files.first.filepath), 'w')
|
||||
expect(File).to receive(:write).with(local_path.join(files.first.filepath), files.first.content)
|
||||
container_pool.copy_files(files)
|
||||
end
|
||||
|
||||
it 'raises an error in case of an IOError' do
|
||||
allow(File).to receive(:open).and_raise(IOError)
|
||||
allow(File).to receive(:write).and_raise(IOError)
|
||||
expect { container_pool.copy_files(files) }.to raise_error(Runner::Error::WorkspaceError, /#{files.first.filepath}/)
|
||||
end
|
||||
|
||||
@ -137,10 +135,10 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
|
||||
context 'when the file is inside a directory' do
|
||||
let(:directory) { 'temp/dir' }
|
||||
let(:files) { [FactoryBot.build(:file, path: directory)] }
|
||||
let(:files) { [build(:file, path: directory)] }
|
||||
|
||||
before do
|
||||
allow(File).to receive(:open)
|
||||
allow(File).to receive(:write)
|
||||
allow(FileUtils).to receive(:mkdir_p).with(local_path)
|
||||
allow(FileUtils).to receive(:mkdir_p).with(local_path.join(directory))
|
||||
end
|
||||
@ -159,7 +157,7 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
end
|
||||
|
||||
context 'when receiving a binary file' do
|
||||
let(:files) { [FactoryBot.build(:file, :image)] }
|
||||
let(:files) { [build(:file, :image)] }
|
||||
|
||||
it 'copies the file inside the workspace' do
|
||||
expect(FileUtils).to receive(:cp).with(files.first.native_file.path, local_path.join(files.first.filepath))
|
||||
@ -168,11 +166,11 @@ describe Runner::Strategy::DockerContainerPool do
|
||||
end
|
||||
|
||||
context 'when receiving multiple files' do
|
||||
let(:files) { FactoryBot.build_list(:file, 3) }
|
||||
let(:files) { build_list(:file, 3) }
|
||||
|
||||
it 'creates all files' do
|
||||
files.each do |file|
|
||||
expect(File).to receive(:open).with(local_path.join(file.filepath), 'w')
|
||||
expect(File).to receive(:write).with(local_path.join(file.filepath), file.content)
|
||||
end
|
||||
container_pool.copy_files(files)
|
||||
end
|
||||
|
@ -3,8 +3,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Runner::Strategy::Poseidon do
|
||||
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
|
||||
let(:execution_environment) { FactoryBot.create :ruby }
|
||||
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||
let(:execution_environment) { create :ruby }
|
||||
let(:poseidon) { described_class.new(runner_id, execution_environment) }
|
||||
let(:error_message) { 'test error message' }
|
||||
let(:response_body) { nil }
|
||||
@ -128,7 +128,7 @@ describe Runner::Strategy::Poseidon do
|
||||
|
||||
describe '::sync_environment' do
|
||||
let(:action) { -> { described_class.sync_environment(execution_environment) } }
|
||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
||||
let(:execution_environment) { create(:ruby) }
|
||||
|
||||
it 'makes the correct request to Poseidon' do
|
||||
faraday_connection = instance_double 'Faraday::Connection'
|
||||
@ -321,7 +321,7 @@ describe Runner::Strategy::Poseidon do
|
||||
|
||||
describe '#copy_files' do
|
||||
let(:file_content) { 'print("Hello World!")' }
|
||||
let(:file) { FactoryBot.build(:file, content: file_content) }
|
||||
let(:file) { build(:file, content: file_content) }
|
||||
let(:action) { -> { poseidon.copy_files([file]) } }
|
||||
let(:encoded_file_content) { Base64.strict_encode64(file.content) }
|
||||
let!(:copy_files_stub) do
|
||||
|
@ -3,7 +3,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe UserMailer do
|
||||
let(:user) { InternalUser.create(FactoryBot.attributes_for(:teacher)) }
|
||||
let(:user) { InternalUser.create(attributes_for(:teacher)) }
|
||||
|
||||
describe '#activation_needed_email' do
|
||||
let(:mail) { described_class.activation_needed_email(user) }
|
||||
|
@ -6,7 +6,7 @@ describe CodeOcean::File do
|
||||
let(:file) { described_class.create.tap {|file| file.update(content: nil, hidden: nil, read_only: nil) } }
|
||||
|
||||
it 'validates the presence of a file type' do
|
||||
expect(file.errors[:file_type_id]).to be_present
|
||||
expect(file.errors[:file_type]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of the hidden flag' do
|
||||
|
@ -11,7 +11,7 @@ describe CodeharborLink do
|
||||
describe '#to_s' do
|
||||
subject { codeharbor_link.to_s }
|
||||
|
||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link) }
|
||||
let(:codeharbor_link) { create(:codeharbor_link) }
|
||||
|
||||
it { is_expected.to eql codeharbor_link.id.to_s }
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ describe Consumer do
|
||||
end
|
||||
|
||||
it 'validates the uniqueness of the OAuth key' do
|
||||
consumer.update(oauth_key: FactoryBot.create(:consumer).oauth_key)
|
||||
consumer.update(oauth_key: create(:consumer).oauth_key)
|
||||
expect(consumer.errors[:oauth_key]).to be_present
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,7 @@ describe ExecutionEnvironment do
|
||||
it 'validates that the Docker image works' do
|
||||
allow(execution_environment).to receive(:validate_docker_image?).and_return(true)
|
||||
allow(execution_environment).to receive(:working_docker_image?).and_return(true)
|
||||
execution_environment.update(FactoryBot.build(:ruby).attributes)
|
||||
execution_environment.update(build(:ruby).attributes)
|
||||
expect(execution_environment).to have_received(:working_docker_image?)
|
||||
end
|
||||
|
||||
@ -81,8 +81,7 @@ describe ExecutionEnvironment do
|
||||
end
|
||||
|
||||
it 'validates the presence of a user' do
|
||||
expect(execution_environment.errors[:user_id]).to be_present
|
||||
expect(execution_environment.errors[:user_type]).to be_present
|
||||
expect(execution_environment.errors[:user]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the format of the exposed ports' do
|
||||
@ -95,7 +94,7 @@ describe ExecutionEnvironment do
|
||||
|
||||
describe '#valid_test_setup?' do
|
||||
context 'with a test command and a testing framework' do
|
||||
before { execution_environment.update(test_command: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
|
||||
before { execution_environment.update(test_command: attributes_for(:ruby)[:test_command], testing_framework: attributes_for(:ruby)[:testing_framework]) }
|
||||
|
||||
it 'is valid' do
|
||||
expect(execution_environment.errors[:test_command]).to be_blank
|
||||
@ -103,7 +102,7 @@ describe ExecutionEnvironment do
|
||||
end
|
||||
|
||||
context 'with a test command but no testing framework' do
|
||||
before { execution_environment.update(test_command: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: nil) }
|
||||
before { execution_environment.update(test_command: attributes_for(:ruby)[:test_command], testing_framework: nil) }
|
||||
|
||||
it 'is invalid' do
|
||||
expect(execution_environment.errors[:test_command]).to be_present
|
||||
@ -111,7 +110,7 @@ describe ExecutionEnvironment do
|
||||
end
|
||||
|
||||
context 'with no test command but a testing framework' do
|
||||
before { execution_environment.update(test_command: nil, testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
|
||||
before { execution_environment.update(test_command: nil, testing_framework: attributes_for(:ruby)[:testing_framework]) }
|
||||
|
||||
it 'is invalid' do
|
||||
expect(execution_environment.errors[:test_command]).to be_present
|
||||
@ -144,7 +143,7 @@ describe ExecutionEnvironment do
|
||||
end
|
||||
|
||||
it 'is true otherwise' do
|
||||
execution_environment.docker_image = FactoryBot.attributes_for(:ruby)[:docker_image]
|
||||
execution_environment.docker_image = attributes_for(:ruby)[:docker_image]
|
||||
execution_environment.pool_size = 1
|
||||
allow(Rails.env).to receive(:test?).and_return(false)
|
||||
expect(execution_environment.send(:validate_docker_image?)).to be true
|
||||
@ -152,7 +151,7 @@ describe ExecutionEnvironment do
|
||||
end
|
||||
|
||||
describe '#working_docker_image?' do
|
||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
||||
let(:execution_environment) { create(:ruby) }
|
||||
let(:working_docker_image?) { execution_environment.send(:working_docker_image?) }
|
||||
let(:runner) { instance_double 'runner' }
|
||||
|
||||
|
@ -4,15 +4,15 @@ require 'rails_helper'
|
||||
|
||||
describe Exercise do
|
||||
let(:exercise) { described_class.create.tap {|exercise| exercise.update(public: nil, token: nil) } }
|
||||
let(:users) { FactoryBot.create_list(:external_user, 10) }
|
||||
let(:users) { create_list(:external_user, 10) }
|
||||
|
||||
def create_submissions
|
||||
FactoryBot.create_list(:submission, 10, cause: 'submit', exercise: exercise, score: Forgery(:basic).number, user: users.sample)
|
||||
create_list(:submission, 10, cause: 'submit', exercise: exercise, score: Forgery(:basic).number, user: users.sample)
|
||||
end
|
||||
|
||||
it 'validates the number of main files' do
|
||||
exercise = FactoryBot.create(:dummy)
|
||||
exercise.files += FactoryBot.create_pair(:file)
|
||||
exercise = create(:dummy)
|
||||
exercise.files += create_pair(:file)
|
||||
expect(exercise).to receive(:valid_main_file?).and_call_original
|
||||
exercise.save
|
||||
expect(exercise.errors[:files]).to be_present
|
||||
@ -37,36 +37,35 @@ describe Exercise do
|
||||
end
|
||||
|
||||
it 'validates the presence of a user' do
|
||||
expect(exercise.errors[:user_id]).to be_present
|
||||
expect(exercise.errors[:user_type]).to be_present
|
||||
expect(exercise.errors[:user]).to be_present
|
||||
end
|
||||
|
||||
context 'when exercise is unpublished' do
|
||||
subject { FactoryBot.build(:dummy, unpublished: true) }
|
||||
subject { build(:dummy, unpublished: true) }
|
||||
|
||||
it { is_expected.not_to validate_presence_of(:execution_environment) }
|
||||
end
|
||||
|
||||
context 'when exercise is not unpublished' do
|
||||
subject { FactoryBot.build(:dummy, unpublished: false) }
|
||||
subject { build(:dummy, unpublished: false) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:execution_environment) }
|
||||
end
|
||||
|
||||
context 'with uuid' do
|
||||
subject { FactoryBot.build(:dummy, uuid: SecureRandom.uuid) }
|
||||
subject { build(:dummy, uuid: SecureRandom.uuid) }
|
||||
|
||||
it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
|
||||
end
|
||||
|
||||
context 'without uuid' do
|
||||
subject { FactoryBot.build(:dummy, uuid: nil) }
|
||||
subject { build(:dummy, uuid: nil) }
|
||||
|
||||
it { is_expected.not_to validate_uniqueness_of(:uuid) }
|
||||
end
|
||||
|
||||
describe '#average_percentage' do
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
let(:exercise) { create(:fibonacci) }
|
||||
|
||||
context 'without submissions' do
|
||||
it 'returns nil' do
|
||||
@ -85,7 +84,7 @@ describe Exercise do
|
||||
end
|
||||
|
||||
describe '#average_score' do
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
let(:exercise) { create(:fibonacci) }
|
||||
|
||||
context 'without submissions' do
|
||||
it 'returns nil' do
|
||||
@ -104,7 +103,7 @@ describe Exercise do
|
||||
end
|
||||
|
||||
describe '#duplicate' do
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
let(:exercise) { create(:fibonacci) }
|
||||
|
||||
after { exercise.duplicate }
|
||||
|
||||
|
@ -6,7 +6,7 @@ describe ExternalUser do
|
||||
let(:user) { described_class.create }
|
||||
|
||||
it 'validates the presence of a consumer' do
|
||||
expect(user.errors[:consumer_id]).to be_present
|
||||
expect(user.errors[:consumer]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of an external ID' do
|
||||
@ -15,7 +15,7 @@ describe ExternalUser do
|
||||
|
||||
describe '#admin?' do
|
||||
it 'is false' do
|
||||
expect(FactoryBot.build(:external_user).admin?).to be false
|
||||
expect(build(:external_user).admin?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -33,7 +33,7 @@ describe ExternalUser do
|
||||
|
||||
describe '#teacher?' do
|
||||
it 'is false' do
|
||||
expect(FactoryBot.build(:external_user).teacher?).to be false
|
||||
expect(build(:external_user).teacher?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +52,6 @@ describe FileType do
|
||||
end
|
||||
|
||||
it 'validates the presence of a user' do
|
||||
expect(file_type.errors[:user_id]).to be_present
|
||||
expect(file_type.errors[:user_type]).to be_present
|
||||
expect(file_type.errors[:user]).to be_present
|
||||
end
|
||||
end
|
||||
|
@ -11,12 +11,12 @@ describe InternalUser do
|
||||
end
|
||||
|
||||
it 'validates the uniqueness of the email address' do
|
||||
user.update(email: FactoryBot.create(:admin).email)
|
||||
user.update(email: create(:admin).email)
|
||||
expect(user.errors[:email]).to be_present
|
||||
end
|
||||
|
||||
context 'when not activated' do
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:user) { create(:teacher) }
|
||||
|
||||
before do
|
||||
user.send(:setup_activation)
|
||||
@ -35,7 +35,7 @@ describe InternalUser do
|
||||
end
|
||||
|
||||
context 'with a pending password reset' do
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:user) { create(:teacher) }
|
||||
|
||||
before { user.deliver_reset_password_instructions! }
|
||||
|
||||
@ -51,7 +51,7 @@ describe InternalUser do
|
||||
end
|
||||
|
||||
context 'when complete' do
|
||||
let(:user) { FactoryBot.create(:teacher, activation_state: 'active') }
|
||||
let(:user) { create(:teacher, activation_state: 'active') }
|
||||
|
||||
it 'does not validate the confirmation of the password' do
|
||||
user.update(password: password, password_confirmation: '')
|
||||
@ -74,8 +74,8 @@ describe InternalUser do
|
||||
|
||||
describe '#admin?' do
|
||||
it 'is only true for admins' do
|
||||
expect(FactoryBot.build(:admin).admin?).to be true
|
||||
expect(FactoryBot.build(:teacher).admin?).to be false
|
||||
expect(build(:admin).admin?).to be true
|
||||
expect(build(:teacher).admin?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@ -93,8 +93,8 @@ describe InternalUser do
|
||||
|
||||
describe '#teacher?' do
|
||||
it 'is only true for teachers' do
|
||||
expect(FactoryBot.build(:admin).teacher?).to be false
|
||||
expect(FactoryBot.build(:teacher).teacher?).to be true
|
||||
expect(build(:admin).teacher?).to be false
|
||||
expect(build(:teacher).teacher?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,10 +3,10 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe RequestForComment do
|
||||
let!(:rfc) { FactoryBot.create(:rfc) }
|
||||
let!(:rfc) { create(:rfc) }
|
||||
|
||||
describe 'scope with_comments' do
|
||||
let!(:rfc2) { FactoryBot.create(:rfc_with_comment) }
|
||||
let!(:rfc2) { create(:rfc_with_comment) }
|
||||
|
||||
it 'includes all RfCs with comments' do
|
||||
expect(described_class.with_comments).to include(rfc2)
|
||||
|
@ -3,12 +3,12 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Runner do
|
||||
let(:runner_id) { FactoryBot.attributes_for(:runner)[:runner_id] }
|
||||
let(:runner_id) { attributes_for(:runner)[:runner_id] }
|
||||
let(:strategy_class) { described_class.strategy_class }
|
||||
let(:strategy) { instance_double(strategy_class) }
|
||||
|
||||
describe 'attribute validation' do
|
||||
let(:runner) { FactoryBot.create :runner }
|
||||
let(:runner) { create :runner }
|
||||
|
||||
it 'validates the presence of the runner id' do
|
||||
described_class.skip_callback(:validation, :before, :request_id)
|
||||
@ -162,8 +162,8 @@ describe Runner do
|
||||
end
|
||||
|
||||
describe 'creation' do
|
||||
let(:user) { FactoryBot.create :external_user }
|
||||
let(:execution_environment) { FactoryBot.create :ruby }
|
||||
let(:user) { create :external_user }
|
||||
let(:execution_environment) { create :ruby }
|
||||
let(:create_action) { -> { described_class.create(user: user, execution_environment: execution_environment) } }
|
||||
|
||||
it 'requests a runner id from the runner management' do
|
||||
@ -187,12 +187,12 @@ describe Runner do
|
||||
it 'does not call the runner management again while a runner id is set' do
|
||||
expect(strategy_class).to receive(:request_from_management).and_return(runner_id).once
|
||||
runner = create_action.call
|
||||
runner.update(user: FactoryBot.create(:external_user))
|
||||
runner.update(user: create(:external_user))
|
||||
end
|
||||
end
|
||||
|
||||
describe '#request_new_id' do
|
||||
let(:runner) { FactoryBot.create :runner }
|
||||
let(:runner) { create :runner }
|
||||
|
||||
context 'when the environment is available in the runner management' do
|
||||
it 'requests the runner management' do
|
||||
@ -240,8 +240,8 @@ describe Runner do
|
||||
end
|
||||
|
||||
describe '::for' do
|
||||
let(:user) { FactoryBot.create :external_user }
|
||||
let(:exercise) { FactoryBot.create :fibonacci }
|
||||
let(:user) { create :external_user }
|
||||
let(:exercise) { create :fibonacci }
|
||||
|
||||
context 'when the runner could not be saved' do
|
||||
before { allow(strategy_class).to receive(:request_from_management).and_return(nil) }
|
||||
@ -252,7 +252,7 @@ describe Runner do
|
||||
end
|
||||
|
||||
context 'when a runner already exists' do
|
||||
let!(:existing_runner) { FactoryBot.create(:runner, user: user, execution_environment: exercise.execution_environment) }
|
||||
let!(:existing_runner) { create(:runner, user: user, execution_environment: exercise.execution_environment) }
|
||||
|
||||
it 'returns the existing runner' do
|
||||
new_runner = described_class.for(user, exercise.execution_environment)
|
||||
|
@ -3,23 +3,22 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Submission do
|
||||
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) }
|
||||
let(:submission) { create(:submission, exercise: create(:dummy)) }
|
||||
|
||||
it 'validates the presence of a cause' do
|
||||
expect(described_class.create.errors[:cause]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of an exercise' do
|
||||
expect(described_class.create.errors[:exercise_id]).to be_present
|
||||
expect(described_class.create.errors[:exercise]).to be_present
|
||||
end
|
||||
|
||||
it 'validates the presence of a user' do
|
||||
expect(described_class.create.errors[:user_id]).to be_present
|
||||
expect(described_class.create.errors[:user_type]).to be_present
|
||||
expect(described_class.create.errors[:user]).to be_present
|
||||
end
|
||||
|
||||
describe '#main_file' do
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:submission) { create(:submission) }
|
||||
|
||||
it "returns the submission's main file" do
|
||||
expect(submission.main_file).to be_a(CodeOcean::File)
|
||||
@ -29,7 +28,7 @@ describe Submission do
|
||||
|
||||
describe '#normalized_score' do
|
||||
context 'with a score' do
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:submission) { create(:submission) }
|
||||
|
||||
before { submission.score = submission.exercise.maximum_score / 2 }
|
||||
|
||||
@ -49,7 +48,7 @@ describe Submission do
|
||||
|
||||
describe '#percentage' do
|
||||
context 'with a score' do
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:submission) { create(:submission) }
|
||||
|
||||
before { submission.score = submission.exercise.maximum_score / 2 }
|
||||
|
||||
@ -69,11 +68,11 @@ describe Submission do
|
||||
|
||||
describe '#siblings' do
|
||||
let(:siblings) { described_class.find_by(user: user).siblings }
|
||||
let(:user) { FactoryBot.create(:external_user) }
|
||||
let(:user) { create(:external_user) }
|
||||
|
||||
before do
|
||||
10.times.each_with_index do |_, index|
|
||||
FactoryBot.create(:submission, exercise: submission.exercise, user: (index.even? ? user : FactoryBot.create(:external_user)))
|
||||
create(:submission, exercise: submission.exercise, user: (index.even? ? user : create(:external_user)))
|
||||
end
|
||||
end
|
||||
|
||||
@ -92,9 +91,9 @@ describe Submission do
|
||||
|
||||
describe '#redirect_to_feedback?' do
|
||||
context 'with no exercise feedback' do
|
||||
let(:exercise) { FactoryBot.create(:dummy) }
|
||||
let(:user) { FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
||||
let(:submission) { FactoryBot.build(:submission, exercise: exercise, user: user) }
|
||||
let(:exercise) { create(:dummy) }
|
||||
let(:user) { build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
||||
let(:submission) { build(:submission, exercise: exercise, user: user) }
|
||||
|
||||
it 'sends 10% of users to feedback page' do
|
||||
expect(submission.send(:redirect_to_feedback?)).to be_truthy
|
||||
@ -102,16 +101,16 @@ describe Submission do
|
||||
|
||||
it 'does not redirect other users' do
|
||||
9.times do |i|
|
||||
submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
||||
submission = build(:submission, exercise: exercise, user: build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
||||
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with little exercise feedback' do
|
||||
let(:exercise) { FactoryBot.create(:dummy_with_user_feedbacks) }
|
||||
let(:user) { FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
||||
let(:submission) { FactoryBot.build(:submission, exercise: exercise, user: user) }
|
||||
let(:exercise) { create(:dummy_with_user_feedbacks) }
|
||||
let(:user) { build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) }
|
||||
let(:submission) { build(:submission, exercise: exercise, user: user) }
|
||||
|
||||
it 'sends 10% of users to feedback page' do
|
||||
expect(submission.send(:redirect_to_feedback?)).to be_truthy
|
||||
@ -119,15 +118,15 @@ describe Submission do
|
||||
|
||||
it 'does not redirect other users' do
|
||||
9.times do |i|
|
||||
submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
||||
submission = build(:submission, exercise: exercise, user: build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1))
|
||||
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with enough exercise feedback' do
|
||||
let(:exercise) { FactoryBot.create(:dummy_with_user_feedbacks, user_feedbacks_count: 42) }
|
||||
let(:user) { FactoryBot.create(:external_user) }
|
||||
let(:exercise) { create(:dummy_with_user_feedbacks, user_feedbacks_count: 42) }
|
||||
let(:user) { create(:external_user) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).to receive(:redirect_to_feedback?).and_return(false)
|
||||
@ -135,7 +134,7 @@ describe Submission do
|
||||
|
||||
it 'sends nobody to feedback page' do
|
||||
30.times do |_i|
|
||||
submission = FactoryBot.create(:submission, exercise: exercise, user: FactoryBot.create(:external_user))
|
||||
submission = create(:submission, exercise: exercise, user: create(:external_user))
|
||||
expect(submission.send(:redirect_to_feedback?)).to be_falsey
|
||||
end
|
||||
end
|
||||
@ -143,7 +142,7 @@ describe Submission do
|
||||
end
|
||||
|
||||
describe '#calculate_score' do
|
||||
let(:runner) { FactoryBot.create :runner }
|
||||
let(:runner) { create :runner }
|
||||
|
||||
before do
|
||||
allow(Runner).to receive(:for).and_return(runner)
|
||||
|
@ -7,15 +7,15 @@ describe Admin::DashboardPolicy do
|
||||
|
||||
permissions :show? do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), :dashboard)
|
||||
expect(policy).to permit(build(:admin), :dashboard)
|
||||
end
|
||||
|
||||
it 'does not grant access to teachers' do
|
||||
expect(policy).not_to permit(FactoryBot.build(:teacher), :dashboard)
|
||||
expect(policy).not_to permit(build(:teacher), :dashboard)
|
||||
end
|
||||
|
||||
it 'does not grant access to external users' do
|
||||
expect(policy).not_to permit(FactoryBot.build(:external_user), :dashboard)
|
||||
expect(policy).not_to permit(build(:external_user), :dashboard)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,15 +5,15 @@ require 'rails_helper'
|
||||
describe CodeOcean::FilePolicy do
|
||||
subject(:policy) { described_class }
|
||||
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
let(:submission) { FactoryBot.create(:submission) }
|
||||
let(:exercise) { create(:fibonacci) }
|
||||
let(:submission) { create(:submission) }
|
||||
|
||||
permissions :create? do
|
||||
context 'when being part of an exercise' do
|
||||
let(:file) { exercise.files.first }
|
||||
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), file)
|
||||
expect(policy).to permit(build(:admin), file)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
@ -22,7 +22,7 @@ describe CodeOcean::FilePolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
||||
expect(policy).not_to permit(build(factory_name), file)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -52,7 +52,7 @@ describe CodeOcean::FilePolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
||||
expect(policy).not_to permit(build(factory_name), file)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -63,7 +63,7 @@ describe CodeOcean::FilePolicy do
|
||||
let(:file) { exercise.files.first }
|
||||
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), file)
|
||||
expect(policy).to permit(build(:admin), file)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
@ -72,7 +72,7 @@ describe CodeOcean::FilePolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
||||
expect(policy).not_to permit(build(factory_name), file)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -82,7 +82,7 @@ describe CodeOcean::FilePolicy do
|
||||
|
||||
it 'does not grant access to anyone' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file)
|
||||
expect(policy).not_to permit(build(factory_name), file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ require 'rails_helper'
|
||||
describe CodeharborLinkPolicy do
|
||||
subject(:policy) { described_class }
|
||||
|
||||
let(:codeharbor_link) { FactoryBot.create(:codeharbor_link) }
|
||||
let(:codeharbor_link) { create(:codeharbor_link) }
|
||||
|
||||
context 'when CodeHarbor link is enabled' do
|
||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
||||
@ -20,7 +20,7 @@ describe CodeharborLinkPolicy do
|
||||
permissions(action) do
|
||||
it 'does not grant access any user' do
|
||||
%i[external_user teacher admin].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.create(factory_name), codeharbor_link)
|
||||
expect(policy).not_to permit(create(factory_name), codeharbor_link)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -30,12 +30,12 @@ describe CodeharborLinkPolicy do
|
||||
permissions(action) do
|
||||
it 'grants access to teachers' do
|
||||
%i[teacher admin].each do |factory_name|
|
||||
expect(policy).to permit(FactoryBot.create(factory_name), codeharbor_link)
|
||||
expect(policy).to permit(create(factory_name), codeharbor_link)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
expect(policy).not_to permit(FactoryBot.create(:external_user), codeharbor_link)
|
||||
expect(policy).not_to permit(create(:external_user), codeharbor_link)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -48,7 +48,7 @@ describe CodeharborLinkPolicy do
|
||||
|
||||
it 'does not grant access to arbitrary users' do
|
||||
%i[external_user admin teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.create(factory_name), codeharbor_link)
|
||||
expect(policy).not_to permit(create(factory_name), codeharbor_link)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -57,7 +57,7 @@ describe CodeharborLinkPolicy do
|
||||
permissions(:enabled?) do
|
||||
it 'reflects the config option' do
|
||||
%i[external_user admin teacher].each do |factory_name|
|
||||
expect(policy).to permit(FactoryBot.create(factory_name), codeharbor_link)
|
||||
expect(policy).to permit(create(factory_name), codeharbor_link)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -75,7 +75,7 @@ describe CodeharborLinkPolicy do
|
||||
permissions(:enabled?) do
|
||||
it 'reflects the config option' do
|
||||
%i[external_user admin teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.create(factory_name), codeharbor_link)
|
||||
expect(policy).not_to permit(create(factory_name), codeharbor_link)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,9 +8,9 @@ describe ConsumerPolicy do
|
||||
%i[create? destroy? edit? index? new? show? update?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), Consumer.new)
|
||||
expect(policy).to permit(build(:admin), Consumer.new)
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), Consumer.new)
|
||||
expect(policy).not_to permit(build(factory_name), Consumer.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,20 +5,20 @@ require 'rails_helper'
|
||||
describe ExecutionEnvironmentPolicy do
|
||||
subject(:policy) { described_class }
|
||||
|
||||
let(:execution_environment) { FactoryBot.build(:ruby) }
|
||||
let(:execution_environment) { build(:ruby) }
|
||||
|
||||
[:index?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), execution_environment)
|
||||
expect(policy).to permit(build(:admin), execution_environment)
|
||||
end
|
||||
|
||||
it 'grants access to teachers' do
|
||||
expect(policy).to permit(FactoryBot.build(:teacher), execution_environment)
|
||||
expect(policy).to permit(build(:teacher), execution_environment)
|
||||
end
|
||||
|
||||
it 'does not grant access to external users' do
|
||||
expect(policy).not_to permit(FactoryBot.build(:external_user), execution_environment)
|
||||
expect(policy).not_to permit(build(:external_user), execution_environment)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -26,7 +26,7 @@ describe ExecutionEnvironmentPolicy do
|
||||
%i[execute_command? shell? statistics? show?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), execution_environment)
|
||||
expect(policy).to permit(build(:admin), execution_environment)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
@ -35,7 +35,7 @@ describe ExecutionEnvironmentPolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), execution_environment)
|
||||
expect(policy).not_to permit(build(factory_name), execution_environment)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -44,7 +44,7 @@ describe ExecutionEnvironmentPolicy do
|
||||
%i[destroy? edit? update? new? create?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), execution_environment)
|
||||
expect(policy).to permit(build(:admin), execution_environment)
|
||||
end
|
||||
|
||||
it 'does not grant access to authors' do
|
||||
@ -53,7 +53,7 @@ describe ExecutionEnvironmentPolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), execution_environment)
|
||||
expect(policy).not_to permit(build(factory_name), execution_environment)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -61,7 +61,7 @@ describe ExecutionEnvironmentPolicy do
|
||||
|
||||
permissions(:sync_all_to_runner_management?) do
|
||||
it 'grants access to the admin' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin))
|
||||
expect(policy).to permit(build(:admin))
|
||||
end
|
||||
|
||||
shared_examples 'it does not grant access' do |user|
|
||||
@ -71,7 +71,7 @@ describe ExecutionEnvironmentPolicy do
|
||||
end
|
||||
|
||||
%i[teacher external_user].each do |user|
|
||||
include_examples 'it does not grant access', FactoryBot.build(user)
|
||||
include_examples 'it does not grant access', FactoryBot.build(user) # rubocop:disable RSpec/FactoryBot/SyntaxMethods
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,13 +5,13 @@ require 'rails_helper'
|
||||
describe ExercisePolicy do
|
||||
subject(:policy) { described_class }
|
||||
|
||||
let(:exercise) { FactoryBot.build(:dummy, public: true) }
|
||||
let(:exercise) { build(:dummy, public: true) }
|
||||
|
||||
permissions :batch_update? do
|
||||
it 'grants access to admins only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), exercise)
|
||||
expect(policy).to permit(build(:admin), exercise)
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), exercise)
|
||||
expect(policy).not_to permit(build(factory_name), exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -19,15 +19,15 @@ describe ExercisePolicy do
|
||||
%i[create? index? new? statistics? feedback? rfcs_for_exercise?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), exercise)
|
||||
expect(policy).to permit(build(:admin), exercise)
|
||||
end
|
||||
|
||||
it 'grants access to teachers' do
|
||||
expect(policy).to permit(FactoryBot.build(:teacher), exercise)
|
||||
expect(policy).to permit(build(:teacher), exercise)
|
||||
end
|
||||
|
||||
it 'does not grant access to external users' do
|
||||
expect(policy).not_to permit(FactoryBot.build(:external_user), exercise)
|
||||
expect(policy).not_to permit(build(:external_user), exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -35,7 +35,7 @@ describe ExercisePolicy do
|
||||
%i[clone? destroy? edit? update?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), exercise)
|
||||
expect(policy).to permit(build(:admin), exercise)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
@ -44,7 +44,7 @@ describe ExercisePolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), exercise)
|
||||
expect(policy).not_to permit(build(factory_name), exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -60,7 +60,7 @@ describe ExercisePolicy do
|
||||
end
|
||||
|
||||
context 'when user has codeharbor_link' do
|
||||
before { user.codeharbor_link = FactoryBot.build(:codeharbor_link) }
|
||||
before { user.codeharbor_link = build(:codeharbor_link) }
|
||||
|
||||
it 'grants access' do
|
||||
expect(policy).to permit(user, exercise)
|
||||
@ -69,14 +69,14 @@ describe ExercisePolicy do
|
||||
end
|
||||
|
||||
context 'when user is admin' do
|
||||
let(:user) { FactoryBot.build(:admin) }
|
||||
let(:user) { build(:admin) }
|
||||
|
||||
it 'does not grant access' do
|
||||
expect(policy).not_to permit(user, exercise)
|
||||
end
|
||||
|
||||
context 'when user has codeharbor_link' do
|
||||
before { user.codeharbor_link = FactoryBot.build(:codeharbor_link) }
|
||||
before { user.codeharbor_link = build(:codeharbor_link) }
|
||||
|
||||
it 'grants access' do
|
||||
expect(policy).to permit(user, exercise)
|
||||
@ -86,14 +86,14 @@ describe ExercisePolicy do
|
||||
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
context "when user is #{factory_name}" do
|
||||
let(:user) { FactoryBot.build(factory_name) }
|
||||
let(:user) { build(factory_name) }
|
||||
|
||||
it 'does not grant access' do
|
||||
expect(policy).not_to permit(user, exercise)
|
||||
end
|
||||
|
||||
context 'when user has codeharbor_link' do
|
||||
before { user.codeharbor_link = FactoryBot.build(:codeharbor_link) }
|
||||
before { user.codeharbor_link = build(:codeharbor_link) }
|
||||
|
||||
it 'does not grant access' do
|
||||
expect(policy).not_to permit(user, exercise)
|
||||
@ -107,7 +107,7 @@ describe ExercisePolicy do
|
||||
[:show?].each do |action|
|
||||
permissions(action) do
|
||||
it 'not grants access to external users' do
|
||||
expect(policy).not_to permit(FactoryBot.build(:external_user), exercise)
|
||||
expect(policy).not_to permit(build(:external_user), exercise)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -116,7 +116,7 @@ describe ExercisePolicy do
|
||||
permissions(action) do
|
||||
it 'grants access to anyone' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).to permit(FactoryBot.build(factory_name), Exercise.new)
|
||||
expect(policy).to permit(build(factory_name), Exercise.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -124,14 +124,14 @@ describe ExercisePolicy do
|
||||
|
||||
describe ExercisePolicy::Scope do
|
||||
describe '#resolve' do
|
||||
let(:admin) { FactoryBot.create(:admin) }
|
||||
let(:external_user) { FactoryBot.create(:external_user) }
|
||||
let(:teacher) { FactoryBot.create(:teacher) }
|
||||
let(:admin) { create(:admin) }
|
||||
let(:external_user) { create(:external_user) }
|
||||
let(:teacher) { create(:teacher) }
|
||||
|
||||
before do
|
||||
[admin, teacher].each do |user|
|
||||
[true, false].each do |public|
|
||||
FactoryBot.create(:dummy, public: public, user_id: user.id, user_type: InternalUser.name)
|
||||
create(:dummy, public: public, user_id: user.id, user_type: InternalUser.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,9 +8,9 @@ describe ExternalUserPolicy do
|
||||
%i[create? destroy? edit? new? show? update?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), ExternalUser.new)
|
||||
expect(policy).to permit(build(:admin), ExternalUser.new)
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), ExternalUser.new)
|
||||
expect(policy).not_to permit(build(factory_name), ExternalUser.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -19,10 +19,10 @@ describe ExternalUserPolicy do
|
||||
[:index?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins and teachers only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), ExternalUser.new)
|
||||
expect(policy).to permit(FactoryBot.build(:teacher), ExternalUser.new)
|
||||
expect(policy).to permit(build(:admin), ExternalUser.new)
|
||||
expect(policy).to permit(build(:teacher), ExternalUser.new)
|
||||
[:external_user].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), ExternalUser.new)
|
||||
expect(policy).not_to permit(build(factory_name), ExternalUser.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,12 +5,12 @@ require 'rails_helper'
|
||||
describe FileTypePolicy do
|
||||
subject(:policy) { described_class }
|
||||
|
||||
let(:file_type) { FactoryBot.build(:dot_rb) }
|
||||
let(:file_type) { build(:dot_rb) }
|
||||
|
||||
%i[destroy? edit? update? new? create? index? show?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), file_type)
|
||||
expect(policy).to permit(build(:admin), file_type)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
@ -19,7 +19,7 @@ describe FileTypePolicy do
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), file_type)
|
||||
expect(policy).not_to permit(build(factory_name), file_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,9 +8,9 @@ describe InternalUserPolicy do
|
||||
%i[create? edit? index? new? show? update?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), InternalUser.new)
|
||||
expect(policy).to permit(build(:admin), InternalUser.new)
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), InternalUser.new)
|
||||
expect(policy).not_to permit(build(factory_name), InternalUser.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -20,16 +20,16 @@ describe InternalUserPolicy do
|
||||
context 'with an admin user' do
|
||||
it 'grants access to no one' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), FactoryBot.build(:admin))
|
||||
expect(policy).not_to permit(build(factory_name), build(:admin))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a non-admin user' do
|
||||
it 'grants access to admins only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), InternalUser.new)
|
||||
expect(policy).to permit(build(:admin), InternalUser.new)
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), FactoryBot.build(:teacher))
|
||||
expect(policy).not_to permit(build(factory_name), build(:teacher))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ describe SubmissionPolicy do
|
||||
permissions :create? do
|
||||
it 'grants access to anyone' do
|
||||
%i[admin external_user teacher].each do |factory_name|
|
||||
expect(policy).to permit(FactoryBot.build(factory_name), Submission.new)
|
||||
expect(policy).to permit(build(factory_name), Submission.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -16,21 +16,21 @@ describe SubmissionPolicy do
|
||||
%i[download_file? render_file? run? score? show? statistics? stop? test?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), Submission.new)
|
||||
expect(policy).to permit(build(:admin), Submission.new)
|
||||
end
|
||||
|
||||
it 'grants access to authors' do
|
||||
user = FactoryBot.create(:external_user)
|
||||
expect(policy).to permit(user, FactoryBot.build(:submission, exercise: Exercise.new, user_id: user.id, user_type: user.class.name))
|
||||
user = create(:external_user)
|
||||
expect(policy).to permit(user, build(:submission, exercise: Exercise.new, user_id: user.id, user_type: user.class.name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
permissions :index? do
|
||||
it 'grants access to admins only' do
|
||||
expect(policy).to permit(FactoryBot.build(:admin), Submission.new)
|
||||
expect(policy).to permit(build(:admin), Submission.new)
|
||||
%i[external_user teacher].each do |factory_name|
|
||||
expect(policy).not_to permit(FactoryBot.build(factory_name), Submission.new)
|
||||
expect(policy).not_to permit(build(factory_name), Submission.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ describe ExerciseService::CheckExternal do
|
||||
subject(:export_service) { described_class.new(uuid: uuid, codeharbor_link: codeharbor_link) }
|
||||
|
||||
let(:uuid) { SecureRandom.uuid }
|
||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
||||
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||
|
||||
it 'assigns uuid' do
|
||||
expect(export_service.instance_variable_get(:@uuid)).to be uuid
|
||||
@ -22,7 +22,7 @@ describe ExerciseService::CheckExternal do
|
||||
subject(:check_external_service) { described_class.call(uuid: uuid, codeharbor_link: codeharbor_link) }
|
||||
|
||||
let(:uuid) { SecureRandom.uuid }
|
||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
||||
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||
let(:response) { {}.to_json }
|
||||
|
||||
before { stub_request(:post, codeharbor_link.check_uuid_url).to_return(body: response) }
|
||||
|
@ -6,8 +6,8 @@ RSpec.describe ExerciseService::PushExternal do
|
||||
describe '.new' do
|
||||
subject(:push_external) { described_class.new(zip: zip, codeharbor_link: codeharbor_link) }
|
||||
|
||||
let(:zip) { ProformaService::ExportTask.call(exercise: FactoryBot.build(:dummy)) }
|
||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
||||
let(:zip) { ProformaService::ExportTask.call(exercise: build(:dummy)) }
|
||||
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||
|
||||
it 'assigns zip' do
|
||||
expect(push_external.instance_variable_get(:@zip)).to be zip
|
||||
@ -21,8 +21,8 @@ RSpec.describe ExerciseService::PushExternal do
|
||||
describe '#execute' do
|
||||
subject(:push_external) { described_class.call(zip: zip, codeharbor_link: codeharbor_link) }
|
||||
|
||||
let(:zip) { ProformaService::ExportTask.call(exercise: FactoryBot.build(:dummy)) }
|
||||
let(:codeharbor_link) { FactoryBot.build(:codeharbor_link) }
|
||||
let(:zip) { ProformaService::ExportTask.call(exercise: build(:dummy)) }
|
||||
let(:codeharbor_link) { build(:codeharbor_link) }
|
||||
let(:status) { 200 }
|
||||
let(:response) { '' }
|
||||
|
||||
|
@ -6,7 +6,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
describe '.new' do
|
||||
subject(:convert_to_task) { described_class.new(exercise: exercise) }
|
||||
|
||||
let(:exercise) { FactoryBot.build(:dummy) }
|
||||
let(:exercise) { build(:dummy) }
|
||||
|
||||
it 'assigns exercise' do
|
||||
expect(convert_to_task.instance_variable_get(:@exercise)).to be exercise
|
||||
@ -18,7 +18,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
let(:convert_to_task) { described_class.new(exercise: exercise) }
|
||||
let(:exercise) do
|
||||
FactoryBot.create(:dummy,
|
||||
create(:dummy,
|
||||
instructions: 'instruction',
|
||||
uuid: SecureRandom.uuid,
|
||||
files: files + tests)
|
||||
@ -46,7 +46,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
context 'when exercise has a mainfile' do
|
||||
let(:files) { [file] }
|
||||
let(:file) { FactoryBot.build(:file) }
|
||||
let(:file) { build(:file) }
|
||||
|
||||
it 'creates a task-file with the correct attributes' do
|
||||
expect(task.files.first).to have_attributes(
|
||||
@ -64,7 +64,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
context 'when exercise has a regular file' do
|
||||
let(:files) { [file] }
|
||||
let(:file) { FactoryBot.build(:file, role: 'regular_file', hidden: hidden, read_only: read_only) }
|
||||
let(:file) { build(:file, role: 'regular_file', hidden: hidden, read_only: read_only) }
|
||||
let(:hidden) { true }
|
||||
let(:read_only) { true }
|
||||
|
||||
@ -98,7 +98,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
end
|
||||
|
||||
context 'when file has an attachment' do
|
||||
let(:file) { FactoryBot.build(:file, :image, role: 'regular_file') }
|
||||
let(:file) { build(:file, :image, role: 'regular_file') }
|
||||
|
||||
it 'creates a task-file with the correct attributes' do
|
||||
expect(task.files.first).to have_attributes(
|
||||
@ -112,7 +112,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
context 'when exercise has a file with role reference implementation' do
|
||||
let(:files) { [file] }
|
||||
let(:file) { FactoryBot.build(:file, role: 'reference_implementation') }
|
||||
let(:file) { build(:file, role: 'reference_implementation') }
|
||||
|
||||
it 'creates a task with one model-solution' do
|
||||
expect(task.model_solutions).to have(1).item
|
||||
@ -140,7 +140,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
end
|
||||
|
||||
context 'when exercise has multiple files with role reference implementation' do
|
||||
let(:files) { FactoryBot.build_list(:file, 2, role: 'reference_implementation') }
|
||||
let(:files) { build_list(:file, 2, role: 'reference_implementation') }
|
||||
|
||||
it 'creates a task with two model-solutions' do
|
||||
expect(task.model_solutions).to have(2).items
|
||||
@ -149,7 +149,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
context 'when exercise has a test' do
|
||||
let(:tests) { [test_file] }
|
||||
let(:test_file) { FactoryBot.build(:test_file) }
|
||||
let(:test_file) { build(:test_file) }
|
||||
# let(:file) { FactoryBot.build(:codeharbor_test_file) }
|
||||
|
||||
it 'creates a task with one test' do
|
||||
@ -178,7 +178,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
end
|
||||
|
||||
context 'when exercise_file is not hidden' do
|
||||
let(:test_file) { FactoryBot.create(:test_file, hidden: false) }
|
||||
let(:test_file) { create(:test_file, hidden: false) }
|
||||
|
||||
it 'creates the test file with the correct attribute' do
|
||||
expect(task.tests.first.files.first).to have_attributes(visible: 'yes')
|
||||
@ -187,7 +187,7 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
end
|
||||
|
||||
context 'when exercise has multiple tests' do
|
||||
let(:tests) { FactoryBot.build_list(:test_file, 2) }
|
||||
let(:tests) { build_list(:test_file, 2) }
|
||||
|
||||
it 'creates a task with two tests' do
|
||||
expect(task.tests).to have(2).items
|
||||
|
@ -9,8 +9,8 @@ describe ProformaService::ConvertTaskToExercise do
|
||||
subject(:convert_to_exercise_service) { described_class.new(task: task, user: user, exercise: exercise) }
|
||||
|
||||
let(:task) { Proforma::Task.new }
|
||||
let(:user) { FactoryBot.build(:teacher) }
|
||||
let(:exercise) { FactoryBot.build(:dummy) }
|
||||
let(:user) { build(:teacher) }
|
||||
let(:exercise) { build(:dummy) }
|
||||
|
||||
it 'assigns task' do
|
||||
expect(convert_to_exercise_service.instance_variable_get(:@task)).to be task
|
||||
@ -28,7 +28,7 @@ describe ProformaService::ConvertTaskToExercise do
|
||||
describe '#execute' do
|
||||
subject(:convert_to_exercise_service) { described_class.call(task: task, user: user, exercise: exercise) }
|
||||
|
||||
before { FactoryBot.create(:dot_txt) }
|
||||
before { create(:dot_txt) }
|
||||
|
||||
let(:task) do
|
||||
Proforma::Task.new(
|
||||
@ -44,7 +44,7 @@ describe ProformaService::ConvertTaskToExercise do
|
||||
tests: tests
|
||||
)
|
||||
end
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:user) { create(:teacher) }
|
||||
let(:files) { [] }
|
||||
let(:tests) { [] }
|
||||
let(:model_solutions) { [] }
|
||||
@ -301,7 +301,7 @@ describe ProformaService::ConvertTaskToExercise do
|
||||
|
||||
context 'when exercise is set' do
|
||||
let(:exercise) do
|
||||
FactoryBot.create(
|
||||
create(
|
||||
:files,
|
||||
title: 'exercise-title',
|
||||
description: 'exercise-description',
|
||||
|
@ -6,7 +6,7 @@ describe ProformaService::ExportTask do
|
||||
describe '.new' do
|
||||
subject(:export_task) { described_class.new(exercise: exercise) }
|
||||
|
||||
let(:exercise) { FactoryBot.build(:dummy) }
|
||||
let(:exercise) { build(:dummy) }
|
||||
|
||||
it 'assigns exercise' do
|
||||
expect(export_task.instance_variable_get(:@exercise)).to be exercise
|
||||
@ -25,7 +25,7 @@ describe ProformaService::ExportTask do
|
||||
subject(:export_task) { described_class.call(exercise: exercise) }
|
||||
|
||||
let(:task) { Proforma::Task.new }
|
||||
let(:exercise) { FactoryBot.build(:dummy) }
|
||||
let(:exercise) { build(:dummy) }
|
||||
let(:exporter) { instance_double('Proforma::Exporter', perform: 'zip') }
|
||||
|
||||
before do
|
||||
|
@ -7,7 +7,7 @@ describe ProformaService::Import do
|
||||
subject(:import_service) { described_class.new(zip: zip, user: user) }
|
||||
|
||||
let(:zip) { Tempfile.new('proforma_test_zip_file') }
|
||||
let(:user) { FactoryBot.build(:teacher) }
|
||||
let(:user) { build(:teacher) }
|
||||
|
||||
it 'assigns zip' do
|
||||
expect(import_service.instance_variable_get(:@zip)).to be zip
|
||||
@ -21,11 +21,11 @@ describe ProformaService::Import do
|
||||
describe '#execute' do
|
||||
subject(:import_service) { described_class.call(zip: zip_file, user: import_user) }
|
||||
|
||||
let(:user) { FactoryBot.create(:teacher) }
|
||||
let(:user) { create(:teacher) }
|
||||
let(:import_user) { user }
|
||||
let(:zip_file) { Tempfile.new('proforma_test_zip_file', encoding: 'ascii-8bit') }
|
||||
let(:exercise) do
|
||||
FactoryBot.create(:dummy,
|
||||
create(:dummy,
|
||||
instructions: 'instruction',
|
||||
execution_environment: execution_environment,
|
||||
files: files + tests,
|
||||
@ -34,7 +34,7 @@ describe ProformaService::Import do
|
||||
end
|
||||
|
||||
let(:uuid) { nil }
|
||||
let(:execution_environment) { FactoryBot.build(:java) }
|
||||
let(:execution_environment) { build(:java) }
|
||||
let(:files) { [] }
|
||||
let(:tests) { [] }
|
||||
let(:exporter) { ProformaService::ExportTask.call(exercise: exercise.reload).string }
|
||||
@ -78,12 +78,12 @@ describe ProformaService::Import do
|
||||
|
||||
context 'when exercise has a mainfile' do
|
||||
let(:files) { [file] }
|
||||
let(:file) { FactoryBot.build(:file) }
|
||||
let(:file) { build(:file) }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
|
||||
context 'when the mainfile is very large' do
|
||||
let(:file) { FactoryBot.build(:file, content: 'test' * (10**5)) }
|
||||
let(:file) { build(:file, content: 'test' * (10**5)) }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
end
|
||||
@ -91,12 +91,12 @@ describe ProformaService::Import do
|
||||
|
||||
context 'when exercise has a regular file' do
|
||||
let(:files) { [file] }
|
||||
let(:file) { FactoryBot.build(:file, role: 'regular_file') }
|
||||
let(:file) { build(:file, role: 'regular_file') }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
|
||||
context 'when file has an attachment' do
|
||||
let(:file) { FactoryBot.build(:file, :image, role: 'regular_file') }
|
||||
let(:file) { build(:file, :image, role: 'regular_file') }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
end
|
||||
@ -104,26 +104,26 @@ describe ProformaService::Import do
|
||||
|
||||
context 'when exercise has a file with role reference implementation' do
|
||||
let(:files) { [file] }
|
||||
let(:file) { FactoryBot.build(:file, role: 'reference_implementation', read_only: true) }
|
||||
let(:file) { build(:file, role: 'reference_implementation', read_only: true) }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
end
|
||||
|
||||
context 'when exercise has multiple files with role reference implementation' do
|
||||
let(:files) { FactoryBot.build_list(:file, 2, role: 'reference_implementation', read_only: true) }
|
||||
let(:files) { build_list(:file, 2, role: 'reference_implementation', read_only: true) }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
end
|
||||
|
||||
context 'when exercise has a test' do
|
||||
let(:tests) { [test] }
|
||||
let(:test) { FactoryBot.build(:test_file) }
|
||||
let(:test) { build(:test_file) }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
end
|
||||
|
||||
context 'when exercise has multiple tests' do
|
||||
let(:tests) { FactoryBot.build_list(:test_file, 2) }
|
||||
let(:tests) { build_list(:test_file, 2) }
|
||||
|
||||
it { is_expected.to be_an_equal_exercise_as exercise }
|
||||
end
|
||||
@ -153,7 +153,7 @@ describe ProformaService::Import do
|
||||
end
|
||||
|
||||
context 'when another user imports the exercise' do
|
||||
let(:import_user) { FactoryBot.create(:teacher) }
|
||||
let(:import_user) { create(:teacher) }
|
||||
|
||||
it 'raises a proforma error' do
|
||||
expect { imported_exercise.save! }.to raise_error Proforma::ExerciseNotOwned
|
||||
|
@ -4,3 +4,7 @@ require 'factory_bot'
|
||||
|
||||
# Use "old" FactoryBot default to allow auto-creating associations for #build
|
||||
FactoryBot.use_parent_strategy = false
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
|
||||
describe FileUploader do
|
||||
let(:file_path) { Rails.root.join('db/seeds/fibonacci/exercise.rb') }
|
||||
let(:uploader) { described_class.new(FactoryBot.create(:file)) }
|
||||
let(:uploader) { described_class.new(create(:file)) }
|
||||
|
||||
before { uploader.store!(File.open(file_path, 'r')) }
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'execution_environments/shell.html.slim' do
|
||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
||||
let(:execution_environment) { create(:ruby) }
|
||||
|
||||
before do
|
||||
assign(:execution_environment, execution_environment)
|
||||
|
@ -3,12 +3,12 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'exercises/implement.html.slim' do
|
||||
let(:exercise) { FactoryBot.create(:fibonacci) }
|
||||
let(:exercise) { create(:fibonacci) }
|
||||
let(:files) { exercise.files.visible }
|
||||
let(:non_binary_files) { files.reject {|file| file.file_type.binary? } }
|
||||
|
||||
before do
|
||||
assign(:current_user, FactoryBot.create(:admin))
|
||||
assign(:current_user, create(:admin))
|
||||
assign(:exercise, exercise)
|
||||
assign(:files, files)
|
||||
assign(:paths, [])
|
||||
|
Reference in New Issue
Block a user