-
Notifications
You must be signed in to change notification settings - Fork 358
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
Rails7 test fixes #9231
Rails7 test fixes #9231
Conversation
:model_name => 'ManageIQ::Providers::CloudManager::Vm', | ||
:model_name => 'VmOrTemplate', |
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 value is from: @report_data_additional_options[:model]
via -- ApplicationHelper#model_to_report_data
Locally, this passed in x_active_tree = :instance_tree
and got the correct model
back in vm_common.rb
So this was passing for me.
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.
So this was passing for me.
With rails 7 or 6.1?
FYI, ui-classic was failing with cross repo + rails 7 without this change.
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.
ok, so this calls post
2 times: explorer
and x_button
.
In the explorer
call, the db
/model
is ManageIQ::Providers::CloudManager::Vm
In the x_button
the db
/model
is VmOrTemplate
.
The explorer
call sets the @report_data_additional_options.model
to the current model, which is ManageIQ::Providers::CloudManager::Vm
.
The x_button
call will reuse the @report_data_additional_options.model
value if it is present.
In 6.1, the x_button
has the instance variable set, so the model
is ManageIQ::Providers::CloudManager::Vm
In 7.0, actionpack-7.0.8.4/lib/action_controller/metal/testing.rb
has a method clear_instance_variables_between_requests
. So @report_data_additional_options
is not set and it sets the model
to the current model, which is VmOrTemplate
.
Conclusions
- The test may be setup incorrectly and the
model
should be the same for both calls. If this is a bug, it was probably always present in the test but did not rear it's head - The test framework changed, this may be just a testing change.
- The expectation for instance variables in controllers may have changed and this may pose a problem in production.
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 agree, this "could" have some impact on our existing UI code. I see get_view and get_db_view processing the show list options if this is not set. If we relied on subsequent requests to have these values persisted over requests, we will likely set rebuilding the options with possibly new/different values on subsequent requests. cc @GilbertCherrie @Fryguy. Great find @kbrock. I've been stumped looking at this one the past few several days off and on.
process_show_list_options(options, db) if @report_data_additional_options.nil? |
if !fetch_data && @report_data_additional_options.nil? |
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.
Going forward, I think, this code is the right code but we'll have to merge this with the rails 7 branch as this will not pass on 6.1
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.
Note, I'll summarize Keenan's findings and put it in the commit message as I will forget about the details in a few days or even hours.
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.
@jrafanie Did you update the commit message? Just waiting for this before merge.
@@ -74,8 +74,8 @@ | |||
|
|||
# http://localhost:3000/vm_infra/show/10000000000449 | |||
it 'can display VM details for vm with ems_custom_attributes and a null attribute name' do | |||
vm_vmware.ems_custom_attributes.push(custom_attr1, custom_attr2) | |||
expect(controller).to receive(:identify_record).and_return(vm_vmware) | |||
vm_vmware.ems_custom_attributes = [custom_attr1, custom_attr2] |
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.
ems_custom_attributes
is an association.
I think <<
may be a better approach
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.
ok, so the issue is the custom attribute was created with a nil
source.
If you create the attribute with :source => "VC"
, then this works great.
I do remember warnings that scopes will not properly pass across for collection.create
. I am not sure if this is related.
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.
WAT. That's crazy. So, why does it work with assignment?
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.
Nice find. It's interesting that I still need the identify_record
twice
change below.
fd2d283
to
aaf37a0
Compare
@@ -65,7 +65,7 @@ | |||
|
|||
let(:custom_attr2) do | |||
FactoryBot.create( | |||
:custom_attribute, | |||
:ems_custom_attribute, |
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.
Thanks for the great sleuthing @kbrock. I changed this to use the ems custom attribute factory which sets source to VC.
@@ -75,7 +75,7 @@ | |||
# http://localhost:3000/vm_infra/show/10000000000449 | |||
it 'can display VM details for vm with ems_custom_attributes and a null attribute name' do | |||
vm_vmware.ems_custom_attributes.push(custom_attr1, custom_attr2) | |||
expect(controller).to receive(:identify_record).and_return(vm_vmware) | |||
expect(controller).to receive(:identify_record).twice.and_return(vm_vmware) |
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 still needed.
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.
agreed. I saw the same thing
It's was unclear at first why we don't hit this in rails 6.1 because on rails 7, we get VmOrTemplate as I would expect from this code: https://github.com/ManageIQ/manageiq-ui-classic/blob/9761b105b3a0038f30c1b933c24bee99ea3daf0b/app/controllers/mixins/actions/vm_actions/ownership.rb#L71-L86 Keenan made the following findings: This calls post 2 times: explorer and x_button. In the explorer call, the db/model is ManageIQ::Providers::CloudManager::Vm In the x_button the db/model is VmOrTemplate. The explorer call sets the report_data_additional_options.model to the current model, which is ManageIQ::Providers::CloudManager::Vm. The x_button call will reuse the report_data_additional_options.model value if it is present. In 6.1, the x_button has the instance variable set, so the model is ManageIQ::Providers::CloudManager::Vm In 7.0, actionpack-7.0.8.4/lib/action_controller/metal/testing.rb has a method clear_instance_variables_between_requests. So report_data_additional_options is not set and it sets the model to the current model, which is VmOrTemplate.
Without this, the source is set to nil and the ems custom attribute may not be persisted correctly, causing a test failure.
aaf37a0
to
63dae15
Compare
Checked commits jrafanie/manageiq-ui-classic@04ce526~...63dae15 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
This is ready for review but depends on rails 7.
Note, this will only pass on rails 7 and is included in the core cross repo:
Depends: