Commit 832ea186 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'delegator-override-validator-subclasses' into 'master'

Include descendants when validating delegator overrides

See merge request gitlab-org/gitlab!83948
parents 68467582 8052e5e7
......@@ -28,7 +28,13 @@ module Gitlab
end
def add_target(target_class)
@target_classes << target_class if target_class
return unless target_class
@target_classes << target_class
# Also include all descendants inheriting from the target,
# to make sure we catch methods that are only defined in some of them.
@target_classes += target_class.descendants
end
# This will make sure allowlist we put into ancestors are all included
......
......@@ -47,6 +47,15 @@ RSpec.describe Gitlab::Utils::DelegatorOverride::Validator do
expect(validator.target_classes).to contain_exactly(target_class)
end
it 'adds all descendants of the target' do
child_class1 = Class.new(target_class)
child_class2 = Class.new(target_class)
grandchild_class = Class.new(child_class2)
validator.add_target(target_class)
expect(validator.target_classes).to contain_exactly(target_class, child_class1, child_class2, grandchild_class)
end
end
describe '#expand_on_ancestors' do
......
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