-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove subclassing hack by not subclassing EMS #23211
Conversation
@@ -263,6 +263,14 @@ def initialize(values = {}) | |||
end | |||
end | |||
|
|||
let(:model) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this up because it was being defined after the tests that were using it.
providera = define_subclass("ProviderA", ExtManagementSystem) | ||
providerb = define_subclass("ProviderB", ExtManagementSystem) | ||
providerc = define_subclass("ProviderC", ExtManagementSystem) | ||
stub_const("ExtManagementSystem", model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change here.
When we call providers_supporting
/ and therefore Ems.subclasses
- it will fetch the subclasses from our generated/stubbed tree. So we've successfully created a separte tree and no longer need to modify the real Ems tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add a comment like "ExtManagementSystem
is used by providers_supporting
"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I could
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
d44b16a
to
1601832
Compare
1601832
to
a678a19
Compare
Checked commit Fryguy@a678a19 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
@kbrock Please review.
This is an alternative to #23190 which avoids the problem by not subclassing ExtManagementSystem, and instead just using the fake parent model like the other tests do. Since it is avoiding the subclassing it also avoids any possible other contamination that may arise in the future or that we just haven't seen yet.
Because
.providers_supporting
actually calls against ExtManagementSystem literally, we just have to stub_const that particular const to point to our fake model class instead. IMO, this is still a fair test because it exercises the code paths we care about. The test against.provider_classes_supporting
does this same type of fake model stubbing, and that method is really the meat of.providers_supporting
anyway. The.providers_supporting
test is really just an extension of the.provider_classes_supporting
test but taking it to the next step of actually querying for the instances.The only caveat I've seen is that technically
ExtManagementSystem
overrides.supported_subclasses
in order to callpermitted_subclasses
, and so by stubbing awayExtManagementSystem
we're no longer testing that strange path. However, the.provider_classes_supporting
test is already ignoring this, and also the.permitted_subclasses
is already tested in the ext_management_system_spec.