diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-04 15:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-04 15:07:48 +0300 |
commit | 8ed0a009f0ae0de789fae01b3cc9bda54aa03965 (patch) | |
tree | dc1006335110a668ad12eb6bbcb514ba6636dea3 /spec/rubocop | |
parent | 48640cf76a1ee0cd515e259d8f3eb2de25ba01c3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/migration/background_migration_base_class_spec.rb | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/background_migration_base_class_spec.rb b/spec/rubocop/cop/migration/background_migration_base_class_spec.rb new file mode 100644 index 00000000000..0a110418139 --- /dev/null +++ b/spec/rubocop/cop/migration/background_migration_base_class_spec.rb @@ -0,0 +1,104 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/migration/background_migration_base_class' + +RSpec.describe RuboCop::Cop::Migration::BackgroundMigrationBaseClass do + subject(:cop) { described_class.new } + + context 'when the migration class inherits from BatchedMigrationJob' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < BatchedMigrationJob + def perform + connection.execute("select 1") + end + end + end + end + RUBY + end + end + + context 'when the migration class inherits from the namespaced BatchedMigrationJob' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < Gitlab::BackgroundMigration::BatchedMigrationJob + def perform + connection.execute("select 1") + end + end + end + end + RUBY + end + end + + context 'when the migration class inherits from the top-level namespaced BatchedMigrationJob' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < ::Gitlab::BackgroundMigration::BatchedMigrationJob + def perform + connection.execute("select 1") + end + end + end + end + RUBY + end + end + + context 'when a nested class is used inside the job class' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < BatchedMigrationJob + class Project < ApplicationRecord + self.table_name = 'projects' + end + + def perform + Project.update!(name: 'hi') + end + end + end + end + RUBY + end + end + + context 'when the migration class inherits from another class' do + it 'registers an offense' do + expect_offense(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob < SomeOtherClass + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} + end + end + end + RUBY + end + end + + context 'when the migration class does not inherit from anything' do + it 'registers an offense' do + expect_offense(<<~RUBY) + module Gitlab + module BackgroundMigration + class MyJob + ^^^^^^^^^^^ #{described_class::MSG} + end + end + end + RUBY + end + end +end |