diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-04 12:09:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-04 12:09:36 +0300 |
commit | 5ba0ad3da6594180ec12d9166f925d9b1a27dce6 (patch) | |
tree | 7a2028f82f76f6031283180f608d54653296a286 /spec/rubocop | |
parent | 2fa68d3a97fd31bf469050e130f0fc95e8944316 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb | 68 | ||||
-rw-r--r-- | spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb | 46 |
2 files changed, 68 insertions, 46 deletions
diff --git a/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb new file mode 100644 index 00000000000..48570c1c8d8 --- /dev/null +++ b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/with_lock_retries_disallowed_method' + +describe RuboCop::Cop::Migration::WithLockRetriesDisallowedMethod do + include CopHelper + + subject(:cop) { described_class.new } + + context 'in migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + it 'registers an offense when `with_lock_retries` block has disallowed method' do + inspect_source('def change; with_lock_retries { disallowed_method }; end') + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + end + end + + it 'registers an offense when `with_lock_retries` block has disallowed methods' do + source = <<~HEREDOC + def change + with_lock_retries do + disallowed_method + + create_table do |t| + t.text :text + end + + other_disallowed_method + + add_column :users, :name + end + end + HEREDOC + + inspect_source(source) + + aggregate_failures do + expect(cop.offenses.size).to eq(2) + expect(cop.offenses.map(&:line)).to eq([3, 9]) + end + end + + it 'registers no offense when `with_lock_retries` has only allowed method' do + inspect_source('def up; with_lock_retries { add_foreign_key :foo, :bar }; end') + + expect(cop.offenses.size).to eq(0) + end + end + + context 'outside of migration' do + it 'registers no offense' do + inspect_source('def change; with_lock_retries { disallowed_method }; end') + + expect(cop.offenses.size).to eq(0) + end + end +end diff --git a/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb deleted file mode 100644 index b42a4a14c67..00000000000 --- a/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../../rubocop/cop/migration/with_lock_retries_without_ddl_transaction' - -describe RuboCop::Cop::Migration::WithLockRetriesWithoutDdlTransaction do - include CopHelper - - let(:valid_source) { 'class MigrationClass < ActiveRecord::Migration[6.0]; def up; with_lock_retries {}; end; end' } - let(:invalid_source) { 'class MigrationClass < ActiveRecord::Migration[6.0]; disable_ddl_transaction!; def up; with_lock_retries {}; end; end' } - - subject(:cop) { described_class.new } - - context 'in migration' do - before do - allow(cop).to receive(:in_migration?).and_return(true) - end - - it 'registers an offense when `with_lock_retries` is used with `disable_ddl_transaction!` method' do - inspect_source(invalid_source) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end - end - - it 'registers no offense when `with_lock_retries` is used inside an `up` method' do - inspect_source(valid_source) - - expect(cop.offenses.size).to eq(0) - end - end - - context 'outside of migration' do - it 'registers no offense' do - inspect_source(invalid_source) - - expect(cop.offenses.size).to eq(0) - end - end -end |