Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provision_request returns a miq_request object instead of a hash of error and miq_request #14987

Merged
merged 3 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but please add a space after the comma to separate the data a little bit. .join(", ")

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 @@ -644,22 +644,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