Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/migration/background_migrations_spec.rb41
-rw-r--r--spec/rubocop/cop/migration/migration_record_spec.rb56
-rw-r--r--spec/rubocop/cop/static_translation_definition_spec.rb54
-rw-r--r--spec/rubocop/formatter/todo_formatter_spec.rb9
-rw-r--r--spec/rubocop/todo_dir_spec.rb6
5 files changed, 121 insertions, 45 deletions
diff --git a/spec/rubocop/cop/migration/background_migrations_spec.rb b/spec/rubocop/cop/migration/background_migrations_spec.rb
new file mode 100644
index 00000000000..3242211ab47
--- /dev/null
+++ b/spec/rubocop/cop/migration/background_migrations_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../../rubocop/cop/migration/background_migrations'
+
+RSpec.describe RuboCop::Cop::Migration::BackgroundMigrations do
+ let(:cop) { described_class.new }
+
+ context 'when queue_background_migration_jobs_by_range_at_intervals is used' do
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ def up
+ queue_background_migration_jobs_by_range_at_intervals('example', 'example', 1, batch_size: 1, track_jobs: true)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Background migrations are deprecated. Please use a Batched Background Migration instead[...]
+ end
+ RUBY
+ end
+ end
+
+ context 'when requeue_background_migration_jobs_by_range_at_intervals is used' do
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ def up
+ requeue_background_migration_jobs_by_range_at_intervals('example', 1)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Background migrations are deprecated. Please use a Batched Background Migration instead[...]
+ end
+ RUBY
+ end
+ end
+
+ context 'when migrate_in is used' do
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ def up
+ migrate_in(1, 'example', 1, ['example'])
+ ^^^^^^^^^^ Background migrations are deprecated. Please use a Batched Background Migration instead[...]
+ end
+ RUBY
+ end
+ end
+end
diff --git a/spec/rubocop/cop/migration/migration_record_spec.rb b/spec/rubocop/cop/migration/migration_record_spec.rb
index bab0ca469df..bfe6228c421 100644
--- a/spec/rubocop/cop/migration/migration_record_spec.rb
+++ b/spec/rubocop/cop/migration/migration_record_spec.rb
@@ -6,53 +6,55 @@ require_relative '../../../../rubocop/cop/migration/migration_record'
RSpec.describe RuboCop::Cop::Migration::MigrationRecord do
subject(:cop) { described_class.new }
- shared_examples 'a disabled cop' do
+ shared_examples 'a disabled cop' do |klass|
it 'does not register any offenses' do
expect_no_offenses(<<~SOURCE)
class MyMigration < Gitlab::Database::Migration[2.0]
- class Project < ActiveRecord::Base
+ class Project < #{klass}
end
end
SOURCE
end
end
- context 'outside of a migration' do
- it_behaves_like 'a disabled cop'
- end
-
- context 'in migration' do
- before do
- allow(cop).to receive(:in_migration?).and_return(true)
+ %w(ActiveRecord::Base ApplicationRecord).each do |klass|
+ context 'outside of a migration' do
+ it_behaves_like 'a disabled cop', klass
end
- context 'in an old migration' do
+ context 'in migration' do
before do
- allow(cop).to receive(:version).and_return(described_class::ENFORCED_SINCE - 5)
+ allow(cop).to receive(:in_migration?).and_return(true)
end
- it_behaves_like 'a disabled cop'
- end
+ context 'in an old migration' do
+ before do
+ allow(cop).to receive(:version).and_return(described_class::ENFORCED_SINCE - 5)
+ end
- context 'that is recent' do
- before do
- allow(cop).to receive(:version).and_return(described_class::ENFORCED_SINCE)
+ it_behaves_like 'a disabled cop', klass
end
- it 'adds an offense if inheriting from ActiveRecord::Base' do
- expect_offense(<<~RUBY)
- class Project < ActiveRecord::Base
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't inherit from ActiveRecord::Base but use MigrationRecord instead.[...]
+ context 'that is recent' do
+ before do
+ allow(cop).to receive(:version).and_return(described_class::ENFORCED_SINCE)
+ end
+
+ it "adds an offense if inheriting from #{klass}" do
+ expect_offense(<<~RUBY)
+ class Project < #{klass}
+ ^^^^^^^^^^^^^^^^#{'^' * klass.length} Don't inherit from ActiveRecord::Base or ApplicationRecord but use MigrationRecord instead.[...]
end
- RUBY
- end
+ RUBY
+ end
- it 'adds an offense if inheriting from ::ActiveRecord::Base' do
- expect_offense(<<~RUBY)
- class Project < ::ActiveRecord::Base
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't inherit from ActiveRecord::Base but use MigrationRecord instead.[...]
+ it "adds an offense if inheriting from ::#{klass}" do
+ expect_offense(<<~RUBY)
+ class Project < ::#{klass}
+ ^^^^^^^^^^^^^^^^^^#{'^' * klass.length} Don't inherit from ActiveRecord::Base or ApplicationRecord but use MigrationRecord instead.[...]
end
- RUBY
+ RUBY
+ end
end
end
end
diff --git a/spec/rubocop/cop/static_translation_definition_spec.rb b/spec/rubocop/cop/static_translation_definition_spec.rb
index 554a7c17a4b..372fc194c56 100644
--- a/spec/rubocop/cop/static_translation_definition_spec.rb
+++ b/spec/rubocop/cop/static_translation_definition_spec.rb
@@ -9,11 +9,7 @@ require_relative '../../../rubocop/cop/static_translation_definition'
RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
using RSpec::Parameterized::TableSyntax
- let(:msg) do
- "The text you're translating will be already in the translated form when it's assigned to the constant. " \
- "When a users changes the locale, these texts won't be translated again. " \
- "Consider moving the translation logic to a method."
- end
+ let(:msg) { described_class::MSG }
subject(:cop) { described_class.new }
@@ -62,7 +58,7 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
}
end
CODE
- <<~CODE
+ <<~CODE,
class MyClass
B = [
[
@@ -72,6 +68,26 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
]
end
CODE
+ <<~CODE,
+ class MyClass
+ field :foo, title: _('A title')
+ ^^^^^^^^^^^^ #{msg}
+ end
+ CODE
+ <<~CODE
+ included do
+ _('a')
+ ^^^^^^ #{msg}
+ end
+ prepended do
+ self.var = _('a')
+ ^^^^^^ #{msg}
+ end
+ class_methods do
+ _('a')
+ ^^^^^^ #{msg}
+ end
+ CODE
]
end
@@ -95,6 +111,13 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
CODE
<<~CODE,
class MyClass
+ def self.method
+ @cache ||= { hello: proc { _("hello") } }
+ end
+ end
+ CODE
+ <<~CODE,
+ class MyClass
def method
@cache ||= { hello: _("hello") }
end
@@ -128,13 +151,30 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
end
end
CODE
- <<~CODE
+ <<~CODE,
Struct.new('SomeClass') do
def text
_('Some translated text')
end
end
CODE
+ <<~CODE,
+ class MyClass
+ field :foo, title: -> { _('A title') }
+ end
+ CODE
+ <<~CODE
+ included do
+ put do
+ _('b')
+ end
+ end
+ class_methods do
+ expose do
+ _('b')
+ end
+ end
+ CODE
]
end
diff --git a/spec/rubocop/formatter/todo_formatter_spec.rb b/spec/rubocop/formatter/todo_formatter_spec.rb
index e1b1de33bfe..fcff028f07d 100644
--- a/spec/rubocop/formatter/todo_formatter_spec.rb
+++ b/spec/rubocop/formatter/todo_formatter_spec.rb
@@ -14,17 +14,18 @@ RSpec.describe RuboCop::Formatter::TodoFormatter do
let(:real_tmp_dir) { File.join(tmp_dir, 'real') }
let(:symlink_tmp_dir) { File.join(tmp_dir, 'symlink') }
let(:rubocop_todo_dir) { "#{symlink_tmp_dir}/.rubocop_todo" }
- let(:options) { { rubocop_todo_dir: rubocop_todo_dir } }
let(:todo_dir) { RuboCop::TodoDir.new(rubocop_todo_dir) }
- subject(:formatter) { described_class.new(stdout, options) }
+ subject(:formatter) { described_class.new(stdout) }
around do |example|
FileUtils.mkdir(real_tmp_dir)
FileUtils.symlink(real_tmp_dir, symlink_tmp_dir)
Dir.chdir(symlink_tmp_dir) do
- example.run
+ described_class.with_base_directory(rubocop_todo_dir) do
+ example.run
+ end
end
end
@@ -38,8 +39,6 @@ RSpec.describe RuboCop::Formatter::TodoFormatter do
let(:offense_autocorrect) { fake_offense('B/AutoCorrect') }
before do
- stub_const("#{described_class}::MAX_OFFENSE_COUNT", 1)
-
stub_rubocop_registry(
'A/Offense' => { autocorrectable: false },
'B/AutoCorrect' => { autocorrectable: true }
diff --git a/spec/rubocop/todo_dir_spec.rb b/spec/rubocop/todo_dir_spec.rb
index ae59def885d..a5c12e23896 100644
--- a/spec/rubocop/todo_dir_spec.rb
+++ b/spec/rubocop/todo_dir_spec.rb
@@ -42,12 +42,6 @@ RSpec.describe RuboCop::TodoDir do
end
end
- describe '#directory' do
- subject { todo_dir.directory }
-
- it { is_expected.to eq(directory) }
- end
-
describe '#read' do
let(:content) { 'a' }