diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/rubocop/cop/migration/background_migration_base_class_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/rubocop/cop/migration/background_migration_base_class_spec.rb')
-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 |