diff --git a/rubocop/cop/ignored_columns.rb b/rubocop/cop/ignored_columns.rb index 1eeb73eaa8490606042734bae1d8413fd7bc747e..4a6f1e4f2d98521de7f92a1faa815f27f812cb89 100644 --- a/rubocop/cop/ignored_columns.rb +++ b/rubocop/cop/ignored_columns.rb @@ -2,7 +2,7 @@ module RuboCop module Cop - # Cop that blacklists the usage of Group.public_or_visible_to_user + # Cop that blacklists the usage of `ActiveRecord::Base.ignored_columns=` directly class IgnoredColumns < RuboCop::Cop::Cop USE_CONCERN_MSG = 'Use `IgnoredColumns` concern instead of adding to `self.ignored_columns`.' WRONG_MODEL_MSG = 'If the model exists in CE and EE, the column has to be ignored ' \ @@ -43,11 +43,19 @@ def used_in_wrong_model? end def ee_model?(path) - path.include?('ee/') + path.include?(ee_directory) + end + + def ee_directory + File.join(rails_root, 'ee') + end + + def rails_root + File.expand_path('../..', __dir__) end def ce_model_exists?(path) - File.exist?(path.gsub(%r{ee/}, '')) + File.exist?(path.gsub(%r{/ee/}, '/')) end end end diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb index 459a4e22f0343b66f4ceda62fc3382edd64b8574..f87b1a1e52087cb502a0afd7516eb457b1f0b3c2 100644 --- a/spec/rubocop/cop/ignored_columns_spec.rb +++ b/spec/rubocop/cop/ignored_columns_spec.rb @@ -43,8 +43,6 @@ class Baz < ApplicationRecord end it 'flags ignore_columns usage in EE model' do - file_path = full_path('ee/app/models/ee/bar.rb') - expect_no_offenses(<<~RUBY, file_path) class Bar < ApplicationRecord ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22' @@ -90,7 +88,7 @@ class Bar < ApplicationRecord private def full_path(path) - rails_root = '../../../../' + rails_root = '../../../' File.expand_path(File.join(rails_root, path), __dir__) end