summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/ignored_columns_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/ignored_columns_spec.rb')
-rw-r--r--spec/rubocop/cop/ignored_columns_spec.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb
index 1c72fedbf31..f87b1a1e520 100644
--- a/spec/rubocop/cop/ignored_columns_spec.rb
+++ b/spec/rubocop/cop/ignored_columns_spec.rb
@@ -14,4 +14,82 @@ RSpec.describe RuboCop::Cop::IgnoredColumns do
end
RUBY
end
+
+ context 'when only CE model exist' do
+ let(:file_path) { full_path('app/models/bar.rb') }
+
+ it 'does not flag ignore_columns usage in CE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+
+ it 'flags ignore_column usage in EE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Baz < ApplicationRecord
+ ignore_column :bar, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+ end
+
+ context 'when only EE model exist' do
+ let(:file_path) { full_path('ee/app/models/ee/bar.rb') }
+
+ before do
+ allow(File).to receive(:exist?).with(full_path('app/models/bar.rb')).and_return(false)
+ end
+
+ it 'flags ignore_columns usage in EE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+
+ it 'flags ignore_column usage in EE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_column :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+ end
+
+ context 'when CE and EE model exist' do
+ let(:file_path) { full_path('ee/app/models/ee/bar.rb') }
+
+ before do
+ allow(File).to receive(:exist?).with(full_path('app/models/bar.rb')).and_return(true)
+ end
+
+ it 'flags ignore_columns usage in EE model' do
+ expect_offense(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If the model exists in CE and EE, [...]
+ end
+ RUBY
+ end
+
+ it 'flags ignore_column usage in EE model' do
+ expect_offense(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_column :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If the model exists in CE and EE, [...]
+ end
+ RUBY
+ end
+ end
+
+ private
+
+ def full_path(path)
+ rails_root = '../../../'
+
+ File.expand_path(File.join(rails_root, path), __dir__)
+ end
end