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

77 lines
2.1 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/cron_worker_context'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Scalability::CronWorkerContext do
2020-03-13 15:44:24 +05:30
subject(:cop) { described_class.new }
it 'adds an offense when including CronjobQueue' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
2020-03-13 15:44:24 +05:30
class SomeWorker
include CronjobQueue
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^ Manually define an ApplicationContext for cronjob-workers.[...]
2020-03-13 15:44:24 +05:30
end
CODE
end
it 'does not add offenses for other workers' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
class SomeWorker
end
CODE
end
it 'does not add an offense when the class defines a context' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
class SomeWorker
include CronjobQueue
with_context user: 'bla'
end
CODE
end
it 'does not add an offense when the worker calls `with_context`' do
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
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
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
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
2020-06-23 00:09:42 +05:30
expect_no_offenses(<<~CODE)
2020-03-13 15:44:24 +05:30
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