Skip to content

Commit

Permalink
Separate queue put from publish event so we don't queue put twice
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Nov 27, 2018
1 parent 879bc8f commit 6a6b595
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/custom_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions spec/models/custom_button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a6b595

Please sign in to comment.