diff --git a/app/models/custom_button.rb b/app/models/custom_button.rb index 9c3f9f057a0..c6b8d951dc7 100644 --- a/app/models/custom_button.rb +++ b/app/models/custom_button.rb @@ -100,7 +100,8 @@ def invoke(target, source = nil) MiqQueue.put(queue_opts(target, args)) end - def publish_event(source, target, args) + def publish_event(source, target, args = nil) + args ||= resource_action.automate_queue_hash(target, {}, User.current_user) Array(target).each { |t| create_event(source, t, args) } end diff --git a/spec/models/custom_button_spec.rb b/spec/models/custom_button_spec.rb index 306380702af..2fb11ed7cfe 100644 --- a/spec/models/custom_button_spec.rb +++ b/spec/models/custom_button_spec.rb @@ -384,5 +384,23 @@ end end end + + describe "publish event" do + context "with blank args" do + it "resource action calls automate_queue_hash" do + expect(resource_action).to receive(:automate_queue_hash).with(vm, {}, user).and_return(:username => "foo") + + User.with_user(user) { custom_button.publish_event('UI', vm) } + end + end + + context "with args" do + it "resource action doesn't call automate_queue_hash" do + expect(resource_action).not_to receive(:automate_queue_hash) + + User.with_user(user) { custom_button.publish_event('UI', vm, :username => "foo") } + end + end + end end end