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
Restore all previous TreeNodeBuilder#build functionality and add specs #12060
Restore all previous TreeNodeBuilder#build functionality and add specs #12060
Conversation
55d1d8c
to
6c70f6d
Compare
Wow, really nice :) I'll do a thorough review tomorrow but I love those tests! <3 :) Btw.. looks like you found a bug, seems like a lot of those entities don't have a defined prefix (note to self - fix that :D) (all those |
@himdel No, not a bug, it is actually how the
|
@NickLaMuro not what I meant.. Compare..
with
All those starting with a dash should have an entry in |
I think we are still talking about the same thing... check the Regardless, I have to fix these tests that are borked, and I want you to have your evening back. See you tomorrow! 😄 |
Oh! You're right, it could be that :) But agreed, tomorrow is a day too :) |
6c70f6d
to
a6592ce
Compare
Adds tests for (almost) every possible class the could be run through the `.build` method from our application, and confirms the result object from it (instead of just confirming it isn't `nil`). This will allow for confidence in refactoring in the future to move away from the current `hash`/`case` setup and confirm functionality. These specs can be moved elsewhere if such a refactoring were to take place, but for now, this allows us to confirm existing functionality with the current behavior. The models added here were gathered through the following method: 1. First, the following commit was checked out to revert the changes to TreeNodeBuilder prior to converting the large `case` in the `.build` to a hash: $ git checkout ee78d9c -- app/presenters/tree_node_builder.rb 2. Then each of the keys in the `case` was run through the following code in a `rails console` to determine which models needed to be tested against: irb(main):001:0> checker_proc = Proc.new {|klass| klass.descendants.map(&:base_class).map(&:to_s).uniq } => #<Proc:0x007f8febe34360@(irb):1> irb(main):002:0> descendants_proc = Proc.new {|klass| klass.descendants.map(&:to_s) } => #<Proc:0x007f8feac69748@(irb):2> irb(main):003:0> check = Proc.new {|klass| puts descendants_proc.call(klass).inspect; puts checker_proc.call(klass).inspect; nil } => #<Proc:0x007f8feaf4b0d8@(irb):3> irb(main):004:0> check.call(AvailabilityZone) ["ManageIQ::Providers::Azure::CloudManager::AvailabilityZone", "ManageIQ::Providers::Google::CloudManager::AvailabilityZone", "ManageIQ::Providers::Openstack::CloudManager::AvailabilityZone", "ManageIQ::Providers::Vmware::CloudManager::AvailabilityZone", "ManageIQ::Providers::Amazon::CloudManager::AvailabilityZone", "ManageIQ::Providers::Openstack::CloudManager::AvailabilityZoneNull"] ["AvailabilityZone"] => nil irb(main):004:0> AvailabilityZone.base_class This allowed it to be determined the class that needed to be included in the specs to confirm previous behavior prior to the commit. It was then used to validate that the new changes worked in the same fashion. Also of note: The "VmOrTemplate node" context in the specs was referring to the `MiqTemplate` key from the original case statement (changed in 54e254e for a bug fix), but was changed to reflect the current implementation (will be updated in the future as well, since the `Vm` key is also a subclass of `VmOrTemplate`).
`Vm` is just a subclass of `VmOrTemplate` as well, so this makes the lookup simpler by just needing the `.base_class` of `object`, and reduces the code in the class. Also restructures the tests to match the new key structure. A few things of note: * VmServer and VmXen are now added as part of the specs for the Vm classes in the "VmOrTemplate node" context. This is because they didn't work prior because they didn't have a lowest level module of `Vm`, and they inherited from VmOrTemplate, which up until this commit, they produced the incorrect node hash for Vm classes. * The vm_node method was re-worked, and removed the logic for using a separate picture if the "Vm" was a template. As the previous sentence probably shows, for the previous usage of this method, everything passed into it would never be a template so this code was never executed to use the "template" images. * The `VmOrTemplate` proc (again, originally the key was `MiqTemplate` prior to the 54e254e changes) originally was using nearly similar code as `Vm` key, but didn't include a tooltip. This is why the slight change to the conditional exists in `vm_node`. * TreeNodeBuilderDatacenter#vm_node was also updated to reflect the new changes that were made in the base class, but retained the difference in tool tip for that subclass (every node includes " (Click to view)" in that class).
These are the 5 classes that inherit from `OrchestrationTemplate`: OrchestrationTemplateCfn OrchestrationTemplateHot OrchestrationTemplateAzure OrchestrationTemplateVnfd ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate Yeah, I don't like that last one either... Since they all are mostly the same, and can use `.base_class` to resolve the `OrchestrationTemplate` key, these have been combined into one key and a helper method has been created for generating the node.
Switching VmdbTableEvm to it's `base_class`, `VmdbTable`, allows for a simpler proc resolution, and is the last key that needs to be found using `.base_class`.
This was a hack to handle keys in the `TreeNodeBuilder::BUILD_NODE_HASH` that weren't base classes. These have now all been converted, so this works without that hack, and only the `Hash` key (which doesn't respond to `.base_class`) should respond to it this way.
a6592ce
to
6da49fa
Compare
Alright, turns out I was wrong, and you were right! Two of the failing tests on CI caught them, and they were for Makes me wonder if we should be doing a |
Checked commits NickLaMuro/manageiq@a7f69bf~...6da49fa with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 |
As for create vs build.. ¯_(ツ)_/¯ maybe? Up to you.. :) |
Tested in the UI, looked in the code, can't find anything wrong 👍 maybe someone else will :) |
@ZitaNemeckova if you could go through the trees as well to see if you notice anything weird... Thanks! |
Restore all previous TreeNodeBuilder#build functionality and add specs (cherry picked from commit 7f18af0)
Euwe Backport details: $ git log -1
commit caace3faa2631d7efc8a0a8b75cba912a0f8a576
Author: Martin Hradil <himdel@seznam.cz>
Date: Fri Oct 21 16:50:14 2016 +0000
Merge pull request #12060 from NickLaMuro/proper_tree_node_builder_keys
Restore all previous TreeNodeBuilder#build functionality and add specs
(cherry picked from commit 7f18af009698082dcc9232329ecef85493b83b1c) |
Purpose
Two fold:
TreeNodeBuilder#build
method to resolve purely by.base_class
method of the object's class in question.Further information regarding the process for building the specs and rational can be found in the commit messages and in the links below
Links
case
statement)