diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/rubocop/cop/sidekiq_api_usage_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/rubocop/cop/sidekiq_api_usage_spec.rb')
-rw-r--r-- | spec/rubocop/cop/sidekiq_api_usage_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/rubocop/cop/sidekiq_api_usage_spec.rb b/spec/rubocop/cop/sidekiq_api_usage_spec.rb new file mode 100644 index 00000000000..79a0774e625 --- /dev/null +++ b/spec/rubocop/cop/sidekiq_api_usage_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' + +require_relative '../../../rubocop/cop/sidekiq_api_usage' + +RSpec.describe RuboCop::Cop::SidekiqApiUsage do + let(:msg) { described_class::MSG } + + context 'when calling Sidekiq::Worker' do + it 'registers no offences for calling skipping_transaction_check' do + expect_no_offenses(<<~PATTERN) + Sidekiq::Worker.skipping_transaction_check do + end + PATTERN + end + + it 'registers no offences for calling raise_inside_transaction_exception' do + expect_no_offenses(<<~PATTERN) + Sidekiq::Worker.raise_inside_transaction_exception(cause: "testing") + PATTERN + end + + it 'registers no offences for calling raise_exception_for_being_inside_a_transaction?' do + expect_no_offenses(<<~PATTERN) + return if Sidekiq::Worker.raise_exception_for_being_inside_a_transaction? + PATTERN + end + + it 'registers offence for calling other Sidekiq::Worker methods' do + expect_offense(<<~PATTERN) + Sidekiq::Worker.drain_all + ^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + end + + it 'does not registers offence when calling Sidekiq::Testing' do + expect_no_offenses(<<~PATTERN) + Sidekiq::Testing.inline! do + create_real_projects! + create_large_projects! + end + PATTERN + end + + it 'registers offence when calling Sidekiq API' do + expect_offense(<<~PATTERN) + Sidekiq::Queue.new('testing').all + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end + + it 'registers offence when assigning Sidekiq API classes' do + expect_offense(<<~PATTERN) + retry_set = Sidekiq::RetrySet.new + ^^^^^^^^^^^^^^^^^^^^^ #{msg} + PATTERN + end +end |