Update bundle (with newest rubocop version) and fix offenses

This commit is contained in:
Sebastian Serth
2022-01-03 18:11:17 +01:00
parent 57e32611ed
commit ea85519163
93 changed files with 968 additions and 985 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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' }

View File

@ -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 }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)