diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 12:52:10 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 12:52:10 +0000 |
commit | dba864470fbcbb6bdd5b94eb510acdce62c962d8 (patch) | |
tree | e8ead0b84e7b814f5891d2c8cd3db2d6b635fb64 /spec/rubocop | |
parent | b7d29500f28ff59c8898cdf889a40d3da908f162 (diff) | |
download | gitlab-ce-dba864470fbcbb6bdd5b94eb510acdce62c962d8.tar.gz |
Add latest changes from gitlab-org/gitlab@12-8-stable-ee
Diffstat (limited to 'spec/rubocop')
3 files changed, 142 insertions, 45 deletions
diff --git a/spec/rubocop/cop/include_action_view_context_spec.rb b/spec/rubocop/cop/include_action_view_context_spec.rb deleted file mode 100644 index c888555b54f..00000000000 --- a/spec/rubocop/cop/include_action_view_context_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../rubocop/cop/include_action_view_context' - -describe RuboCop::Cop::IncludeActionViewContext do - include CopHelper - - subject(:cop) { described_class.new } - - context 'when `ActionView::Context` is included' do - let(:source) { 'include ActionView::Context' } - let(:correct_source) { 'include ::Gitlab::ActionViewOutput::Context' } - - it 'registers an offense' do - inspect_source(source) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['ActionView::Context']) - end - end - - it 'autocorrects to the right version' do - autocorrected = autocorrect_source(source) - - expect(autocorrected).to eq(correct_source) - end - end - - context 'when `ActionView::Context` is not included' do - it 'registers no offense' do - inspect_source('include Context') - - aggregate_failures do - expect(cop.offenses.size).to eq(0) - end - end - end -end diff --git a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb new file mode 100644 index 00000000000..8107cfa8957 --- /dev/null +++ b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' +require_relative '../../../support/helpers/expect_offense' +require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context' + +describe RuboCop::Cop::Scalability::BulkPerformWithContext do + include CopHelper + include ExpectOffense + + subject(:cop) { described_class.new } + + it "adds an offense when calling bulk_perform_async" do + inspect_source(<<~CODE.strip_indent) + Worker.bulk_perform_async(args) + CODE + + expect(cop.offenses.size).to eq(1) + end + + it "adds an offense when calling bulk_perform_in" do + inspect_source(<<~CODE.strip_indent) + diffs.each_batch(of: BATCH_SIZE) do |relation, index| + ids = relation.pluck_primary_key.map { |id| [id] } + DeleteDiffFilesWorker.bulk_perform_in(index * 5.minutes, ids) + end + CODE + + expect(cop.offenses.size).to eq(1) + end + + it "does not add an offense for migrations" do + allow(cop).to receive(:in_migration?).and_return(true) + + inspect_source(<<~CODE.strip_indent) + Worker.bulk_perform_in(args) + CODE + + expect(cop.offenses.size).to eq(0) + end + + it "does not add an offence for specs" do + allow(cop).to receive(:in_spec?).and_return(true) + + inspect_source(<<~CODE.strip_indent) + Worker.bulk_perform_in(args) + CODE + + expect(cop.offenses.size).to eq(0) + end + + it "does not add an offense for scheduling BackgroundMigrations" do + inspect_source(<<~CODE.strip_indent) + BackgroundMigrationWorker.bulk_perform_in(args) + CODE + + expect(cop.offenses.size).to eq(0) + end +end diff --git a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb new file mode 100644 index 00000000000..460514d9bed --- /dev/null +++ b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' +require_relative '../../../support/helpers/expect_offense' +require_relative '../../../../rubocop/cop/scalability/cron_worker_context' + +describe RuboCop::Cop::Scalability::CronWorkerContext do + include CopHelper + include ExpectOffense + + subject(:cop) { described_class.new } + + it 'adds an offense when including CronjobQueue' do + inspect_source(<<~CODE.strip_indent) + class SomeWorker + include CronjobQueue + end + CODE + + expect(cop.offenses.size).to eq(1) + end + + it 'does not add offenses for other workers' do + expect_no_offenses(<<~CODE.strip_indent) + class SomeWorker + end + CODE + end + + it 'does not add an offense when the class defines a context' do + expect_no_offenses(<<~CODE.strip_indent) + class SomeWorker + include CronjobQueue + + with_context user: 'bla' + end + CODE + end + + it 'does not add an offense when the worker calls `with_context`' do + expect_no_offenses(<<~CODE.strip_indent) + class SomeWorker + include CronjobQueue + + def perform + with_context(user: 'bla') do + # more work + end + end + end + CODE + end + + it 'does not add an offense when the worker calls `bulk_perform_async_with_contexts`' do + expect_no_offenses(<<~CODE.strip_indent) + class SomeWorker + include CronjobQueue + + def perform + SomeOtherWorker.bulk_perform_async_with_contexts(things, + arguments_proc: -> (thing) { thing.id }, + context_proc: -> (thing) { { project: thing.project } }) + end + end + CODE + end + + it 'does not add an offense when the worker calls `bulk_perform_in_with_contexts`' do + expect_no_offenses(<<~CODE.strip_indent) + class SomeWorker + include CronjobQueue + + def perform + SomeOtherWorker.bulk_perform_in_with_contexts(10.minutes, things, + arguments_proc: -> (thing) { thing.id }, + context_proc: -> (thing) { { project: thing.project } }) + end + end + CODE + end +end |