2020-02-19 13:09:10 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 14:10:07 -04:00
|
|
|
require 'rubocop_spec_helper'
|
2020-02-19 13:09:10 -05:00
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/migration/schedule_async'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
|
2020-02-19 13:09:10 -05:00
|
|
|
let(:cop) { described_class.new }
|
|
|
|
let(:source) do
|
|
|
|
<<~SOURCE
|
|
|
|
def up
|
|
|
|
BackgroundMigrationWorker.perform_async(ClazzName, "Bar", "Baz")
|
|
|
|
end
|
|
|
|
SOURCE
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a disabled cop' do
|
|
|
|
it 'does not register any offenses' do
|
2021-02-17 16:09:06 -05:00
|
|
|
expect_no_offenses(source)
|
2020-02-19 13:09:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'outside of a migration' do
|
|
|
|
it_behaves_like 'a disabled cop'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in a migration' do
|
|
|
|
before do
|
|
|
|
allow(cop).to receive(:in_migration?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in an old migration' do
|
|
|
|
before do
|
|
|
|
allow(cop).to receive(:version).and_return(described_class::ENFORCED_SINCE - 5)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a disabled cop'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'that is recent' do
|
|
|
|
before do
|
|
|
|
allow(cop).to receive(:version).and_return(described_class::ENFORCED_SINCE + 5)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'BackgroundMigrationWorker.perform_async' do
|
2022-01-10 10:14:26 -05:00
|
|
|
it 'adds an offense when calling `BackgroundMigrationWorker.peform_async`' do
|
2021-02-17 16:09:06 -05:00
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def up
|
|
|
|
BackgroundMigrationWorker.perform_async(ClazzName, "Bar", "Baz")
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
|
|
|
end
|
|
|
|
RUBY
|
2020-02-19 13:09:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-07 07:12:27 -05:00
|
|
|
context 'CiDatabaseWorker.perform_async' do
|
|
|
|
it 'adds an offense when calling `CiDatabaseWorker.peform_async`' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def up
|
|
|
|
CiDatabaseWorker.perform_async(ClazzName, "Bar", "Baz")
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
context 'BackgroundMigrationWorker.perform_in' do
|
2022-01-10 10:14:26 -05:00
|
|
|
it 'adds an offense' do
|
2021-02-17 16:09:06 -05:00
|
|
|
expect_offense(<<~RUBY)
|
2020-02-19 13:09:10 -05:00
|
|
|
def up
|
|
|
|
BackgroundMigrationWorker
|
2021-02-17 16:09:06 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
2020-02-19 13:09:10 -05:00
|
|
|
.perform_in(delay, ClazzName, "Bar", "Baz")
|
|
|
|
end
|
2021-02-17 16:09:06 -05:00
|
|
|
RUBY
|
2020-02-19 13:09:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-07 07:12:27 -05:00
|
|
|
context 'CiDatabaseWorker.perform_in' do
|
|
|
|
it 'adds an offense' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def up
|
|
|
|
CiDatabaseWorker
|
|
|
|
^^^^^^^^^^^^^^^^ Don't call [...]
|
|
|
|
.perform_in(delay, ClazzName, "Bar", "Baz")
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
context 'BackgroundMigrationWorker.bulk_perform_async' do
|
2022-01-10 10:14:26 -05:00
|
|
|
it 'adds an offense' do
|
2021-02-17 16:09:06 -05:00
|
|
|
expect_offense(<<~RUBY)
|
2020-02-19 13:09:10 -05:00
|
|
|
def up
|
|
|
|
BackgroundMigrationWorker
|
2021-02-17 16:09:06 -05:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
2020-02-19 13:09:10 -05:00
|
|
|
.bulk_perform_async(jobs)
|
|
|
|
end
|
2021-02-17 16:09:06 -05:00
|
|
|
RUBY
|
2020-02-19 13:09:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-07 07:12:27 -05:00
|
|
|
context 'CiDatabaseWorker.bulk_perform_async' do
|
|
|
|
it 'adds an offense' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def up
|
|
|
|
BackgroundMigration::CiDatabaseWorker
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
|
|
|
.bulk_perform_async(jobs)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
context 'BackgroundMigrationWorker.bulk_perform_in' do
|
2022-01-10 10:14:26 -05:00
|
|
|
it 'adds an offense' do
|
2021-02-17 16:09:06 -05:00
|
|
|
expect_offense(<<~RUBY)
|
2020-02-19 13:09:10 -05:00
|
|
|
def up
|
2022-02-07 07:12:27 -05:00
|
|
|
::BackgroundMigrationWorker
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
|
|
|
.bulk_perform_in(5.minutes, jobs)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'CiDatabaseWorker.bulk_perform_in' do
|
|
|
|
it 'adds an offense' do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
def up
|
|
|
|
::BackgroundMigration::CiDatabaseWorker
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
|
2020-02-19 13:09:10 -05:00
|
|
|
.bulk_perform_in(5.minutes, jobs)
|
|
|
|
end
|
2021-02-17 16:09:06 -05:00
|
|
|
RUBY
|
2020-02-19 13:09:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|