diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-29 12:08:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-29 12:08:03 +0300 |
commit | ad2789aeba21edaadcbdc06523462e6fd87d4ba1 (patch) | |
tree | 319403c595130a4f78fae367c7cedc88466dd9db /spec/rubocop | |
parent | 2add640cfc67c927eb41cf542ef39ecda4c456c1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb b/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb new file mode 100644 index 00000000000..499351b3585 --- /dev/null +++ b/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/migration/sidekiq_queue_migrate' + +RSpec.describe RuboCop::Cop::Migration::SidekiqQueueMigrate do + subject(:cop) { described_class.new } + + def source(meth = 'change') + "def #{meth}; sidekiq_queue_migrate 'queue', to: 'new_queue'; end" + end + + context 'when in a regular migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + allow(cop).to receive(:in_post_deployment_migration?).and_return(false) + end + + %w(up down change any_other_method).each do |method_name| + it "registers an offense when sidekiq_queue_migrate is used in ##{method_name}" do + expect_offense(<<~RUBY) + def #{method_name} + sidekiq_queue_migrate 'queue', to: 'new_queue' + ^^^^^^^^^^^^^^^^^^^^^ `sidekiq_queue_migrate` must only be used in post-deployment migrations + end + RUBY + end + end + end + + context 'when in a post-deployment migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + allow(cop).to receive(:in_post_deployment_migration?).and_return(true) + end + + it 'registers no offense' do + expect_no_offenses(source) + end + end + + context 'when outside of a migration' do + it 'registers no offense' do + expect_no_offenses(source) + end + end +end |