Function to get a list of delegated methods
What does this MR do and why?
MR is split from !101841 (closed) to make it easier to review.
Rails doesn't provide a function to get delegated methods in a class. Because of that, tests rely on manually maintained lists, which is unreliable. This MR adds the function for project test. The function already helped to detect shadowed delegation in !103852 (merged), and missing delegation field that is added in this MR.
The delegate()
function is checking actual method source using https://github.com/banister/method_source gem that is pulled by pry
, railties
and view_component
gems.
$ gem dependency method_source --reverse-dependencies
Gem method_source-1.0.0
rake (~> 0.9, development)
rspec (~> 3.6, development)
Used by
pry-0.14.2 (method_source (~> 1.0))
pry-0.13.1 (method_source (~> 1.0))
railties-6.1.7.2 (method_source (>= 0))
view_component-2.74.1 (method_source (~> 1.0))
Questions:
- I don't know where to place
delegate()
method for reuse? - Should it be committed upstream?
- I wish I left a better explanation why I filter out methods ending in
=
. - Some methods don't have source. Need to document why this happen.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
- The test should pass with the new code the same way it was beforee
rspec ./spec/models/project_spec.rb:1063 # Project delegation when ci_cd_settings is destroyed but project is not allows methods delegated to ci_cd_settings to be nil
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.