Apply automatic rubocop fixes

This commit is contained in:
Sebastian Serth
2021-05-14 10:51:44 +02:00
parent fe4000916c
commit 6cbecb5b39
440 changed files with 2705 additions and 1853 deletions

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'
describe CodeOcean::File do
let(:file) { described_class.create.tap { |file| file.update(content: nil, hidden: nil, read_only: nil) } }
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
@ -24,7 +26,7 @@ describe CodeOcean::File do
end
context 'as a teacher-defined test' do
before(:each) { file.update(role: 'teacher_defined_test') }
before { file.update(role: 'teacher_defined_test') }
it 'validates the presence of a feedback message' do
expect(file.errors[:feedback_message]).to be_present
@ -41,7 +43,7 @@ describe CodeOcean::File do
end
context 'with another file type' do
before(:each) { file.update(role: 'regular_file') }
before { file.update(role: 'regular_file') }
it 'validates the absence of a feedback message' do
file.update(feedback_message: 'Your solution is not correct yet.')

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe CodeharborLink do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Consumer do

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'
describe ExecutionEnvironment do
let(:execution_environment) { described_class.create.tap { |execution_environment| execution_environment.update(network_enabled: nil) } }
let(:execution_environment) { described_class.create.tap {|execution_environment| execution_environment.update(network_enabled: nil) } }
it 'validates that the Docker image works', docker: true do
expect(execution_environment).to receive(:validate_docker_image?).and_return(true)
@ -69,7 +71,7 @@ describe ExecutionEnvironment do
describe '#valid_test_setup?' do
context 'with a test command and a testing framework' do
before(:each) { 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: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
it 'is valid' do
expect(execution_environment.errors[:test_command]).to be_blank
@ -77,7 +79,7 @@ describe ExecutionEnvironment do
end
context 'with a test command but no testing framework' do
before(:each) { execution_environment.update(test_command: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: nil) }
before { execution_environment.update(test_command: FactoryBot.attributes_for(:ruby)[:test_command], testing_framework: nil) }
it 'is invalid' do
expect(execution_environment.errors[:test_command]).to be_present
@ -85,7 +87,7 @@ describe ExecutionEnvironment do
end
context 'with no test command but a testing framework' do
before(:each) { execution_environment.update(test_command: nil, testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
before { execution_environment.update(test_command: nil, testing_framework: FactoryBot.attributes_for(:ruby)[:testing_framework]) }
it 'is invalid' do
expect(execution_environment.errors[:test_command]).to be_present
@ -93,7 +95,7 @@ describe ExecutionEnvironment do
end
context 'with no test command and no testing framework' do
before(:each) { execution_environment.update(test_command: nil, testing_framework: nil) }
before { execution_environment.update(test_command: nil, testing_framework: nil) }
it 'is valid' do
expect(execution_environment.errors[:test_command]).to be_blank
@ -121,7 +123,8 @@ describe ExecutionEnvironment do
describe '#working_docker_image?', docker: true do
let(:working_docker_image?) { execution_environment.send(:working_docker_image?) }
before(:each) { expect(DockerClient).to receive(:find_image_by_tag).and_return(Object.new) }
before { expect(DockerClient).to receive(:find_image_by_tag).and_return(Object.new) }
it 'instantiates a Docker client' do
expect(DockerClient).to receive(:new).with(execution_environment: execution_environment).and_call_original

View File

@ -1,13 +1,13 @@
# frozen_string_literal: true
require 'rails_helper'
describe Exercise do
let(:exercise) { described_class.create.tap { |exercise| exercise.update(public: nil, token: nil) } }
let(:exercise) { described_class.create.tap {|exercise| exercise.update(public: nil, token: nil) } }
let(:users) { FactoryBot.create_list(:external_user, 10) }
def create_submissions
10.times do
FactoryBot.create(:submission, cause: 'submit', exercise: exercise, score: Forgery(:basic).number, user: users.sample)
end
FactoryBot.create_list(:submission, 10, cause: 'submit', exercise: exercise, score: Forgery(:basic).number, user: users.sample)
end
it 'validates the number of main files' do
@ -75,10 +75,10 @@ describe Exercise do
end
context 'with submissions' do
before(:each) { create_submissions }
before { create_submissions }
it 'returns the average score expressed as a percentage' do
maximum_percentages = exercise.submissions.group_by(&:user_id).values.map { |submission| submission.sort_by(&:score).last.score / exercise.maximum_score * 100 }
maximum_percentages = exercise.submissions.group_by(&:user_id).values.map {|submission| submission.max_by(&:score).score / exercise.maximum_score * 100 }
expect(exercise.average_percentage).to eq(maximum_percentages.average.round(2))
end
end
@ -94,10 +94,10 @@ describe Exercise do
end
context 'with submissions' do
before(:each) { create_submissions }
before { create_submissions }
it "returns the average of all users' maximum scores" do
maximum_scores = exercise.submissions.group_by(&:user_id).values.map { |submission| submission.sort_by(&:score).last.score }
maximum_scores = exercise.submissions.group_by(&:user_id).values.map {|submission| submission.max_by(&:score).score }
expect(exercise.average_score).to be_within(0.1).of(maximum_scores.average)
end
end
@ -105,7 +105,8 @@ describe Exercise do
describe '#duplicate' do
let(:exercise) { FactoryBot.create(:fibonacci) }
after(:each) { exercise.duplicate }
after { exercise.duplicate }
it 'duplicates the exercise' do
expect(exercise).to receive(:dup).and_call_original

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ExternalUser do

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'
describe FileType do
let(:file_type) { described_class.create.tap { |file_type| file_type.update(binary: nil, executable: nil, renderable: nil) } }
let(:file_type) { described_class.create.tap {|file_type| file_type.update(binary: nil, executable: nil, renderable: nil) } }
it 'validates the presence of the binary flag' do
expect(file_type.errors[:binary]).to be_present
@ -10,7 +12,7 @@ describe FileType do
end
context 'when binary' do
before(:each) { file_type.update(binary: true) }
before { file_type.update(binary: true) }
it 'does not validate the presence of an editor mode' do
expect(file_type.errors[:editor_mode]).not_to be_present
@ -22,7 +24,7 @@ describe FileType do
end
context 'when not binary' do
before(:each) { file_type.update(binary: false) }
before { file_type.update(binary: false) }
it 'validates the presence of an editor mode' do
expect(file_type.errors[:editor_mode]).to be_present

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe InternalUser do
@ -16,7 +18,7 @@ describe InternalUser do
context 'when not activated' do
let(:user) { FactoryBot.create(:teacher) }
before(:each) do
before do
user.send(:setup_activation)
user.send(:send_activation_needed_email!)
end
@ -34,7 +36,8 @@ describe InternalUser do
context 'with a pending password reset' do
let(:user) { FactoryBot.create(:teacher) }
before(:each) { user.deliver_reset_password_instructions! }
before { user.deliver_reset_password_instructions! }
it 'validates the confirmation of the password' do
user.update(password: password, password_confirmation: '')

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Submission do
@ -28,7 +30,8 @@ describe Submission do
describe '#normalized_score' do
context 'with a score' do
let(:submission) { FactoryBot.create(:submission) }
before(:each) { submission.score = submission.exercise.maximum_score / 2 }
before { submission.score = submission.exercise.maximum_score / 2 }
it 'returns the score as a value between 0 and 1' do
expect(0..1).to include(submission.normalized_score)
@ -36,7 +39,7 @@ describe Submission do
end
context 'without a score' do
before(:each) { submission.score = nil }
before { submission.score = nil }
it 'returns 0' do
expect(submission.normalized_score).to be 0
@ -47,7 +50,8 @@ describe Submission do
describe '#percentage' do
context 'with a score' do
let(:submission) { FactoryBot.create(:submission) }
before(:each) { submission.score = submission.exercise.maximum_score / 2 }
before { submission.score = submission.exercise.maximum_score / 2 }
it 'returns the score expressed as a percentage' do
expect(0..100).to include(submission.percentage)
@ -55,7 +59,7 @@ describe Submission do
end
context 'without a score' do
before(:each) { submission.score = nil }
before { submission.score = nil }
it 'returns 0' do
expect(submission.percentage).to be 0
@ -67,7 +71,7 @@ describe Submission do
let(:siblings) { described_class.find_by(user: user).siblings }
let(:user) { FactoryBot.create(:external_user) }
before(:each) do
before do
10.times.each_with_index do |_, index|
FactoryBot.create(:submission, exercise: submission.exercise, user: (index.even? ? user : FactoryBot.create(:external_user)))
end
@ -87,11 +91,10 @@ describe Submission do
end
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) { 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) }
it 'sends 10% of users to feedback page' do
expect(submission.send(:redirect_to_feedback?)).to be_truthy
@ -106,9 +109,9 @@ describe Submission do
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) { 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) }
it 'sends 10% of users to feedback page' do
expect(submission.send(:redirect_to_feedback?)).to be_truthy
@ -123,15 +126,15 @@ describe Submission do
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) { FactoryBot.create(:dummy_with_user_feedbacks, user_feedbacks_count: 42) }
let(:user) { FactoryBot.create(:external_user) }
before do
allow_any_instance_of(described_class).to receive(:redirect_to_feedback?).and_return(false)
end
it 'sends nobody to feedback page' do
30.times do |i|
30.times do |_i|
submission = FactoryBot.create(:submission, exercise: exercise, user: FactoryBot.create(:external_user))
expect(submission.send(:redirect_to_feedback?)).to be_falsey
end