Skip to content

Commit

Permalink
Merge pull request #14987 from mkanoor/bz_1447793
Browse files Browse the repository at this point in the history
provision_request returns a miq_request object instead of a hash of error and miq_request
(cherry picked from commit 2b2aff4)

https://bugzilla.redhat.com/show_bug.cgi?id=1448506
  • Loading branch information
gmcculloug authored and simaishi committed May 5, 2017
1 parent 9322d31 commit 19e141d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ def self.create_from_options(options)
private_class_method :create_from_options

def provision_request(user, options = nil, request_options = nil)
provision_workflow(user, options, request_options).submit_request
result = provision_workflow(user, options, request_options).submit_request
raise result[:errors].join(", ") if result[:errors].any?
result[:request]
end

def provision_workflow(user, dialog_options = nil, request_options = nil)
Expand Down
35 changes: 24 additions & 11 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,22 +662,35 @@
end
end

describe "#provision_request" do
it "provision's a service template " do
user = FactoryGirl.create(:user, :userid => "barney")
resource_action = FactoryGirl.create(:resource_action, :action => "Provision")
service_template = FactoryGirl.create(:service_template,
:resource_actions => [resource_action])
hash = {:target => service_template, :initiator => 'control'}
workflow = instance_double(ResourceActionWorkflow)
context "#provision_request" do
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(: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
expect(ResourceActionWorkflow).to(receive(:new)
.with({}, user, resource_action, hash).and_return(workflow))
expect(workflow).to receive(:submit_request)
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')

service_template.provision_request(user, {'ordered_by' => 'fred'},
{:initiator => 'control'})
expect(service_template.provision_request(user, arg1, arg2)).to eq(miq_request)
end

it "provision's a service template with errors" do
expect(ResourceActionWorkflow).to(receive(:new)
.with({}, 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
end
end
Expand Down

0 comments on commit 19e141d

Please sign in to comment.