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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 12:16:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 12:16:11 +0300
commitedaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch)
tree11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/rubocop
parentd8a5691316400a0f7ec4f83832698f1988eb27c1 (diff)
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/code_reuse_helpers_spec.rb73
-rw-r--r--spec/rubocop/cop/database/establish_connection_spec.rb29
-rw-r--r--spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb58
-rw-r--r--spec/rubocop/cop/migration/schedule_async_spec.rb32
4 files changed, 95 insertions, 97 deletions
diff --git a/spec/rubocop/code_reuse_helpers_spec.rb b/spec/rubocop/code_reuse_helpers_spec.rb
index 3220cff1681..d437ada85ee 100644
--- a/spec/rubocop/code_reuse_helpers_spec.rb
+++ b/spec/rubocop/code_reuse_helpers_spec.rb
@@ -315,76 +315,11 @@ RSpec.describe RuboCop::CodeReuseHelpers do
end
end
- describe '#ee?' do
- before do
- stub_env('FOSS_ONLY', nil)
- allow(File).to receive(:exist?).with(ee_file_path) { true }
- end
-
- it 'returns true when ee/app/models/license.rb exists' do
- expect(cop.ee?).to eq(true)
- end
- end
-
- describe '#jh?' do
- context 'when jh directory exists and EE_ONLY is not set' do
- before do
- stub_env('EE_ONLY', nil)
-
- allow(Dir).to receive(:exist?).with(File.expand_path('../../jh', __dir__)) { true }
- end
-
- context 'when ee/app/models/license.rb exists' do
- before do
- allow(File).to receive(:exist?).with(ee_file_path) { true }
- end
-
- context 'when FOSS_ONLY is not set' do
- before do
- stub_env('FOSS_ONLY', nil)
- end
-
- it 'returns true' do
- expect(cop.jh?).to eq(true)
- end
- end
-
- context 'when FOSS_ONLY is set to 1' do
- before do
- stub_env('FOSS_ONLY', '1')
- end
+ %w[ee? jh?].each do |method_name|
+ it "delegates #{method_name} to GitlabEdition" do
+ expect(GitlabEdition).to receive(method_name)
- it 'returns false' do
- expect(cop.jh?).to eq(false)
- end
- end
- end
-
- context 'when ee/app/models/license.rb not exist' do
- before do
- allow(File).to receive(:exist?).with(ee_file_path) { false }
- end
-
- context 'when FOSS_ONLY is not set' do
- before do
- stub_env('FOSS_ONLY', nil)
- end
-
- it 'returns true' do
- expect(cop.jh?).to eq(false)
- end
- end
-
- context 'when FOSS_ONLY is set to 1' do
- before do
- stub_env('FOSS_ONLY', '1')
- end
-
- it 'returns false' do
- expect(cop.jh?).to eq(false)
- end
- end
- end
+ cop.public_send(method_name)
end
end
end
diff --git a/spec/rubocop/cop/database/establish_connection_spec.rb b/spec/rubocop/cop/database/establish_connection_spec.rb
new file mode 100644
index 00000000000..a3c27d33cb0
--- /dev/null
+++ b/spec/rubocop/cop/database/establish_connection_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_relative '../../../../rubocop/cop/database/establish_connection'
+
+RSpec.describe RuboCop::Cop::Database::EstablishConnection do
+ subject(:cop) { described_class.new }
+
+ it 'flags the use of ActiveRecord::Base.establish_connection' do
+ expect_offense(<<~CODE)
+ ActiveRecord::Base.establish_connection
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
+ CODE
+ end
+
+ it 'flags the use of ActiveRecord::Base.establish_connection with arguments' do
+ expect_offense(<<~CODE)
+ ActiveRecord::Base.establish_connection(:foo)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
+ CODE
+ end
+
+ it 'flags the use of SomeModel.establish_connection' do
+ expect_offense(<<~CODE)
+ SomeModel.establish_connection
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
+ CODE
+ end
+end
diff --git a/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb b/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb
new file mode 100644
index 00000000000..aa63259288d
--- /dev/null
+++ b/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../../rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction'
+
+RSpec.describe RuboCop::Cop::Migration::PreventGlobalEnableLockRetriesWithDisableDdlTransaction do
+ subject(:cop) { described_class.new }
+
+ context 'when in migration' do
+ before do
+ allow(cop).to receive(:in_migration?).and_return(true)
+ end
+
+ it 'registers an offense when `enable_lock_retries` and `disable_ddl_transaction` is used together' do
+ code = <<~RUBY
+ class SomeMigration < ActiveRecord::Migration[6.0]
+ enable_lock_retries!
+ disable_ddl_transaction!
+ end
+ RUBY
+
+ expect_offense(<<~RUBY, node: code, msg: described_class::MSG)
+ class SomeMigration < ActiveRecord::Migration[6.0]
+ enable_lock_retries!
+ disable_ddl_transaction!
+ ^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
+ end
+ RUBY
+ end
+
+ it 'registers no offense when `enable_lock_retries!` is used' do
+ expect_no_offenses(<<~RUBY)
+ class SomeMigration < ActiveRecord::Migration[6.0]
+ enable_lock_retries!
+ end
+ RUBY
+ end
+
+ it 'registers no offense when `disable_ddl_transaction!` is used' do
+ expect_no_offenses(<<~RUBY)
+ class SomeMigration < ActiveRecord::Migration[6.0]
+ disable_ddl_transaction!
+ end
+ RUBY
+ end
+ end
+
+ context 'when outside of migration' do
+ it 'registers no offense' do
+ expect_no_offenses(<<~RUBY)
+ class SomeMigration
+ enable_lock_retries!
+ disable_ddl_transaction!
+ end
+ RUBY
+ end
+ end
+end
diff --git a/spec/rubocop/cop/migration/schedule_async_spec.rb b/spec/rubocop/cop/migration/schedule_async_spec.rb
index b89acb6db41..5f848dd9b66 100644
--- a/spec/rubocop/cop/migration/schedule_async_spec.rb
+++ b/spec/rubocop/cop/migration/schedule_async_spec.rb
@@ -43,24 +43,18 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
end
context 'BackgroundMigrationWorker.perform_async' do
- it 'adds an offense when calling `BackgroundMigrationWorker.peform_async` and corrects', :aggregate_failures do
+ it 'adds an offense when calling `BackgroundMigrationWorker.peform_async`' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker.perform_async(ClazzName, "Bar", "Baz")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
end
RUBY
-
- expect_correction(<<~RUBY)
- def up
- migrate_async(ClazzName, "Bar", "Baz")
- end
- RUBY
end
end
context 'BackgroundMigrationWorker.perform_in' do
- it 'adds an offense and corrects', :aggregate_failures do
+ it 'adds an offense' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
@@ -68,17 +62,11 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
.perform_in(delay, ClazzName, "Bar", "Baz")
end
RUBY
-
- expect_correction(<<~RUBY)
- def up
- migrate_in(delay, ClazzName, "Bar", "Baz")
- end
- RUBY
end
end
context 'BackgroundMigrationWorker.bulk_perform_async' do
- it 'adds an offense and corrects', :aggregate_failures do
+ it 'adds an offense' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
@@ -86,17 +74,11 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
.bulk_perform_async(jobs)
end
RUBY
-
- expect_correction(<<~RUBY)
- def up
- bulk_migrate_async(jobs)
- end
- RUBY
end
end
context 'BackgroundMigrationWorker.bulk_perform_in' do
- it 'adds an offense and corrects', :aggregate_failures do
+ it 'adds an offense' do
expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
@@ -104,12 +86,6 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
.bulk_perform_in(5.minutes, jobs)
end
RUBY
-
- expect_correction(<<~RUBY)
- def up
- bulk_migrate_in(5.minutes, jobs)
- end
- RUBY
end
end
end