diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-04 18:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-04 18:08:40 +0300 |
commit | 6b833f1e0340e00fdee074da9c42c0d4e07a46d2 (patch) | |
tree | 6fc3a7a2f8a02fec8d1e7561b453d33eb4048dad /spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb | |
parent | 88a0824944720b6edaaef56376713541b9a02118 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb')
-rw-r--r-- | spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
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 |