Skip to content
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

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

Fryguy
Copy link
Member

@Fryguy Fryguy commented Sep 27, 2024

@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 call permitted_subclasses, and so by stubbing away ExtManagementSystem 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.

@@ -263,6 +263,14 @@ def initialize(values = {})
end
end

let(:model) do
Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member

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"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I could

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@miq-bot
Copy link
Member

miq-bot commented Oct 1, 2024

Checked commit Fryguy@a678a19 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
1 file checked, 0 offenses detected
Everything looks fine. 🍪

@kbrock kbrock merged commit c4e8ef0 into ManageIQ:master Oct 15, 2024
12 checks passed
@Fryguy Fryguy deleted the fix_subclasses_hack branch October 15, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants