Commit a4409dd4 authored by Corinna Wiesner's avatar Corinna Wiesner

Secure path logic against any other directory with ee in it

The logic was breaking for a path that included ee in its name other
than the ee/ directory, e.g. employee/ or gitlab-ee/. This is fixed
with a better detection of a file within the ee directory.
parent 2504bf9b
......@@ -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 @@ module RuboCop
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
......
......@@ -43,8 +43,6 @@ RSpec.describe RuboCop::Cop::IgnoredColumns do
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 @@ RSpec.describe RuboCop::Cop::IgnoredColumns do
private
def full_path(path)
rails_root = '../../../../'
rails_root = '../../../'
File.expand_path(File.join(rails_root, path), __dir__)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment