diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 15:07:59 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 15:07:59 +0000 |
commit | 71c5863d7b1ca9836a7d7703f35750cd726a9846 (patch) | |
tree | f6d74be15157d527ffc648212df141293a36a330 /spec/rubocop | |
parent | 39fa7d1eeb2dba52f0601128f3ac91f57d19866e (diff) | |
download | gitlab-ce-71c5863d7b1ca9836a7d7703f35750cd726a9846.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
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 new file mode 100644 index 00000000000..b42a4a14c67 --- /dev/null +++ b/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb @@ -0,0 +1,46 @@ +# 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 |