diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-19 03:08:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-19 03:08:01 +0300 |
commit | 1caa60060b2f9e3417ab335e2f1dea1064163434 (patch) | |
tree | 01c0d5825bd345ee625bb70b7433c6e10307fcce /spec/rubocop/cop/migration | |
parent | 7f8330873c1a5860b8a9a52d111083a65d210249 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop/cop/migration')
-rw-r--r-- | spec/rubocop/cop/migration/add_column_with_default_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/add_column_with_default_spec.rb b/spec/rubocop/cop/migration/add_column_with_default_spec.rb new file mode 100644 index 00000000000..3d2315ddfa1 --- /dev/null +++ b/spec/rubocop/cop/migration/add_column_with_default_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/add_column_with_default' + +describe RuboCop::Cop::Migration::AddColumnWithDefault do + include CopHelper + + let(:cop) { described_class.new } + + context 'outside of a migration' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + def up + add_reference(:projects, :users) + end + RUBY + end + end + + context 'in a migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + let(:offense) { '`add_column_with_default` with `allow_null: false` may cause prolonged lock situations and downtime, see https://gitlab.com/gitlab-org/gitlab/issues/38060' } + + it 'registers an offense when specifying allow_null: false' do + expect_offense(<<~RUBY) + def up + add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: false) + ^^^^^^^^^^^^^^^^^^^^^^^ #{offense} + end + RUBY + end + + it 'registers no offense when specifying allow_null: true' do + expect_no_offenses(<<~RUBY) + def up + add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: true) + end + RUBY + end + + it 'registers no offense when allow_null is not specified' do + expect_no_offenses(<<~RUBY) + def up + add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true) + end + RUBY + end + + it 'registers no offense for application_settings (whitelisted table)' do + expect_no_offenses(<<~RUBY) + def up + add_column_with_default(:application_settings, :another_column, :boolean, default: true, allow_null: false) + end + RUBY + end + end +end |