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

Force targets to be an array so we can each them in cb run on multiple objects #18056

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Oct 4, 2018

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1628224

... #18042 failed cause it's sometimes not an array that we should be checking for when running CBs on multiple things, mea culpa.

related:

ManageIQ/manageiq-automation_engine#258

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 4, 2018

@miq-bot add_label bug
@miq-bot assign @gmcculloug
@miq-bot add_reviewer @bdunne, @tinaafitz

@d-m-u d-m-u changed the title Use size rather than a check that fails for ActiveRecord::Relation [WIP] Use size rather than a check that fails for ActiveRecord::Relation Oct 4, 2018
@@ -96,7 +96,7 @@ def invoke(target, source = nil)
end

def publish_event(source, target, args)
target.kind_of?(Array) ? target.each { |t| create_event(source, t, args) } : create_event(source, target, args)
target.size > 1 ? target.each { |t| create_event(source, t, args) } : create_event(source, target, args)
Copy link
Member

Choose a reason for hiding this comment

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

I think target.kind_of?(Enumerable) would be more accurate, right?

Copy link
Member

Choose a reason for hiding this comment

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

Could we simplify this line to: Array(target).each { |t| create_event(source, t, args) }

@d-m-u d-m-u force-pushed the use_whoops_size_rather_than_possibly_nonexistent_array branch from 405c88d to 24b0e80 Compare October 4, 2018 15:01
@d-m-u d-m-u changed the title [WIP] Use size rather than a check that fails for ActiveRecord::Relation Force targets to be an array so we can each them in cb run on multiple objects Oct 4, 2018
@miq-bot miq-bot added the bug label Oct 4, 2018
@miq-bot
Copy link
Member

miq-bot commented Oct 4, 2018

@d-m-u 'bdunne, tinaafitz' is an invalid reviewer, ignoring...

let(:vm3) { FactoryGirl.create(:vm_vmware) }
let!(:vm) { FactoryGirl.create(:vm_vmware) }
let!(:vm2) { FactoryGirl.create(:vm_vmware) }
let!(:vm3) { FactoryGirl.create(:vm_vmware) }
Copy link
Member

Choose a reason for hiding this comment

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

Why the change to let!. Variables vm2 and vm3 are only used in one test but will not get created for each.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bdunne, is allow(Vm).to receive(all) ... better than let! here? Or ... something else?

Copy link
Member

Choose a reason for hiding this comment

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

Are they needed for the rest of the tests? If not, https://github.com/ManageIQ/manageiq/pull/18056/files#diff-71376e22701f18c6f0be76915e41ef84R331 should create them, so you shouldn't need let! or the allow(Vm).to receive(:all)....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@d-m-u d-m-u force-pushed the use_whoops_size_rather_than_possibly_nonexistent_array branch from 24b0e80 to e1ad456 Compare October 5, 2018 13:50
let(:vm3) { FactoryGirl.create(:vm_vmware) }
let(:vm) { FactoryGirl.create(:vm_vmware) }
let(:vm2) { FactoryGirl.create(:vm_vmware) }
let(:vm3) { FactoryGirl.create(:vm_vmware) }
Copy link
Member

Choose a reason for hiding this comment

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

I like that after a few rounds of changes the sole purpose here is to undo the alignment with the let blocks below. 😝

@d-m-u d-m-u force-pushed the use_whoops_size_rather_than_possibly_nonexistent_array branch from e1ad456 to e9b1983 Compare October 5, 2018 13:59
@miq-bot
Copy link
Member

miq-bot commented Oct 5, 2018

Checked commit d-m-u@e9b1983 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. ⭐

@gmcculloug gmcculloug merged commit ead55ec into ManageIQ:master Oct 5, 2018
@gmcculloug gmcculloug added this to the Sprint 96 Ending Oct 8, 2018 milestone Oct 5, 2018
@d-m-u d-m-u deleted the use_whoops_size_rather_than_possibly_nonexistent_array branch October 5, 2018 15:04
simaishi pushed a commit that referenced this pull request Oct 5, 2018
…ibly_nonexistent_array

Force targets to be an array so we can each them in cb run on multiple objects

(cherry picked from commit ead55ec)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1628224
@simaishi
Copy link
Contributor

simaishi commented Oct 5, 2018

Hammer backport details:

$ git log -1
commit 1310fd6601221b8940e73edfdc7dbbaeba8d6271
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Fri Oct 5 10:51:47 2018 -0400

    Merge pull request #18056 from d-m-u/use_whoops_size_rather_than_possibly_nonexistent_array
    
    Force targets to be an array so we can each them in cb run on multiple objects
    
    (cherry picked from commit ead55ecf0c3b576028caaa3103b7b2b190508c7c)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1628224

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.

5 participants