debian-mirror-gitlab/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Scalability::BulkPerformWithContext do
2020-03-13 15:44:24 +05:30
subject(:cop) { described_class.new }
it "adds an offense when calling bulk_perform_async" do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
2020-03-13 15:44:24 +05:30
Worker.bulk_perform_async(args)
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `Worker.bulk_perform_async_with_contexts` [...]
2020-03-13 15:44:24 +05:30
CODE
end
it "adds an offense when calling bulk_perform_in" do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
2020-03-13 15:44:24 +05:30
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)
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `Worker.bulk_perform_async_with_contexts` [...]
2020-03-13 15:44:24 +05:30
end
CODE
end
it "does not add an offense for migrations" do
allow(cop).to receive(:in_migration?).and_return(true)
2021-03-11 19:13:27 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
Worker.bulk_perform_in(args)
CODE
end
it "does not add an offence for specs" do
allow(cop).to receive(:in_spec?).and_return(true)
2021-03-11 19:13:27 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
Worker.bulk_perform_in(args)
CODE
end
it "does not add an offense for scheduling BackgroundMigrations" do
2021-03-11 19:13:27 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
BackgroundMigrationWorker.bulk_perform_in(args)
CODE
end
end