Skip to content

Commit

Permalink
Make prov workflow use the right values and add option to not rerun m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
d-m-u committed Jun 26, 2018
1 parent bd0e686 commit 86e5305
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/models/resource_action_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def load_dialog(resource_action, values, options)
dialog.target_resource = @target
if options[:display_view_only]
dialog.init_fields_with_values_for_request(values)
elsif options[:refresh]
elsif options[:refresh] || options[:submit_workflow]
dialog.load_values_into_fields(values)
else
dialog.initialize_value_context(values)
Expand Down
12 changes: 8 additions & 4 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,15 @@ def provision_request(user, options = nil, request_options = nil)
def provision_workflow(user, dialog_options = nil, request_options = nil)
dialog_options ||= {}
request_options ||= {}
ra_options = { :target => self, :initiator => request_options[:initiator] }
ResourceActionWorkflow.new({}, user,
provision_action, ra_options).tap do |wf|
ra_options = {
:target => self,
:initiator => request_options[:initiator],
:submit_workflow => request_options[:submit_workflow]
}

ResourceActionWorkflow.new(dialog_options, user, provision_action, ra_options).tap do |wf|
wf.request_options = request_options
dialog_options.each { |key, value| wf.set_value(key, value) }
# dialog_options.each { |key, value| wf.set_value(key, value) }
end
end

Expand Down
12 changes: 5 additions & 7 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -808,29 +808,27 @@
let(:user) { FactoryGirl.create(:user, :userid => "barney") }
let(:resource_action) { FactoryGirl.create(:resource_action, :action => "Provision") }
let(:service_template) { FactoryGirl.create(:service_template, :resource_actions => [resource_action]) }
let(:hash) { {:target => service_template, :initiator => 'control'} }
let(:hash) { {:target => service_template, :initiator => 'control', :submit_workflow => nil} }
let(:workflow) { instance_double(ResourceActionWorkflow) }
let(:miq_request) { FactoryGirl.create(:service_template_provision_request) }
let(:good_result) { { :errors => [], :request => miq_request } }
let(:bad_result) { { :errors => %w(Error1 Error2), :request => miq_request } }
let(:arg1) { {'ordered_by' => 'fred'} }
let(:arg2) { {:initiator => 'control'} }

it "provision's a service template without errors" do
it "provisions a service template without errors" do
expect(ResourceActionWorkflow).to(receive(:new)
.with({}, user, resource_action, hash).and_return(workflow))
.with({'ordered_by' => 'fred'}, user, resource_action, hash).and_return(workflow))
expect(workflow).to receive(:submit_request).and_return(good_result)
expect(workflow).to receive(:set_value).with('ordered_by', 'fred')
expect(workflow).to receive(:request_options=).with(:initiator => 'control')

expect(service_template.provision_request(user, arg1, arg2)).to eq(miq_request)
end

it "provision's a service template with errors" do
it "provisions a service template with errors" do
expect(ResourceActionWorkflow).to(receive(:new)
.with({}, user, resource_action, hash).and_return(workflow))
.with({'ordered_by' => 'fred'}, user, resource_action, hash).and_return(workflow))
expect(workflow).to receive(:submit_request).and_return(bad_result)
expect(workflow).to receive(:set_value).with('ordered_by', 'fred')
expect(workflow).to receive(:request_options=).with(:initiator => 'control')
expect { service_template.provision_request(user, arg1, arg2) }.to raise_error(RuntimeError)
end
Expand Down

0 comments on commit 86e5305

Please sign in to comment.