Skip to content

Commit

Permalink
Merge pull request #18056 from d-m-u/use_whoops_size_rather_than_poss…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
gmcculloug authored and simaishi committed Oct 5, 2018
1 parent 7853eb4 commit 1310fd6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/models/custom_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Array(target).each { |t| create_event(source, t, args) }
end

def create_event(source, target, args)
Expand Down
49 changes: 35 additions & 14 deletions spec/models/custom_button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,43 @@
)
end

it "with multiple vms" do
Timecop.freeze(Time.now.utc) do
User.with_user(user) { custom_button.send(method, [vm, vm2, vm3], 'UI') }
expect(CustomButtonEvent.first.timestamp).to be_within(0.01).of(Time.now.utc)
describe "multiple vms" do
it "with an array" do
Timecop.freeze(Time.now.utc) do
User.with_user(user) { custom_button.send(method, [vm, vm2, vm3], 'UI') }
expect(CustomButtonEvent.first.timestamp).to be_within(0.01).of(Time.now.utc)
end

expect(CustomButtonEvent.count).to eq(3)
expect(CustomButtonEvent.first).to have_attributes(
:source => 'UI',
:target_id => vm.id,
:target_type => 'VmOrTemplate',
:type => 'CustomButtonEvent',
:event_type => 'button.trigger.start',
:user_id => user.id,
:full_data => a_hash_including(:automate_entry_point => "/SYSTEM/PROCESS/Request")
)
end

expect(CustomButtonEvent.count).to eq(3)
expect(CustomButtonEvent.first).to have_attributes(
:source => 'UI',
:target_id => vm.id,
:target_type => 'VmOrTemplate',
:type => 'CustomButtonEvent',
:event_type => 'button.trigger.start',
:user_id => user.id,
:full_data => a_hash_including(:automate_entry_point => "/SYSTEM/PROCESS/Request")
)
it "with an ActiveRecord::Relation" do
vm && vm2 && vm3
Timecop.freeze(Time.now.utc) do
User.with_user(user) { custom_button.send(method, Vm.all, 'UI') }
expect(CustomButtonEvent.first.timestamp).to be_within(0.01).of(Time.now.utc)
end

expect(CustomButtonEvent.count).to eq(3)
expect(CustomButtonEvent.first).to have_attributes(
:source => 'UI',
:target_id => vm.id,
:target_type => 'VmOrTemplate',
:type => 'CustomButtonEvent',
:event_type => 'button.trigger.start',
:user_id => user.id,
:full_data => a_hash_including(:automate_entry_point => "/SYSTEM/PROCESS/Request")
)
end
end
end
end
Expand Down

0 comments on commit 1310fd6

Please sign in to comment.