Skip to content

Commit

Permalink
Merge pull request #18099 from d-m-u/fixing_merge_conflict_on_bz1635673
Browse files Browse the repository at this point in the history
[GAPRINDASHVILI] Add flag for init of defaults in fields on g
  • Loading branch information
simaishi authored Oct 15, 2018
2 parents aa2df14 + be4d802 commit 5f1530c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 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 @@ -107,7 +107,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[:provision_workflow]
elsif options[:provision_workflow] || options[:init_defaults]
dialog.initialize_value_context(values)
dialog.load_values_into_fields(values, false)
elsif options[:refresh] || options[:submit_workflow]
Expand Down
8 changes: 1 addition & 7 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,7 @@ def order(user_or_id, options = nil, request_options = {}, schedule_time = nil)
def provision_workflow(user, dialog_options = nil, request_options = {})
dialog_options ||= {}
request_options.delete(:provision_workflow) if request_options[:submit_workflow]

ra_options = {
:target => self,
:initiator => request_options[:initiator],
:submit_workflow => request_options[:submit_workflow],
:provision_workflow => request_options[:provision_workflow]
}
ra_options = request_options.slice(:initiator, :init_defaults, :provision_workflow, :submit_workflow).merge(:target => self)

ResourceActionWorkflow.new(dialog_options, user, provision_action, ra_options).tap do |wf|
wf.request_options = request_options
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@
:maindb: ExtManagementSystem
:container_deployment_wizard: false
:transformation: true
:run_automate_methods_on_service_api_submit: false
:prototype:
:queue_type: miq_queue
:artemis:
Expand Down
9 changes: 9 additions & 0 deletions spec/models/resource_action_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@
end
end

context "when the options set init_defaults to true" do
let(:options) { {:init_defaults => true} }
it "calls init_fields_with_values_for_request" do
expect(dialog).to receive(:initialize_value_context).with(values).ordered
expect(dialog).to receive(:load_values_into_fields).with(values, false).ordered
ResourceActionWorkflow.new(values, nil, resource_action, options)
end
end

context "when the options are set to a refresh request" do
let(:options) { {:refresh => true} }

Expand Down
19 changes: 19 additions & 0 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,25 @@
let(:arg1) { {'ordered_by' => 'fred'} }
let(:arg2) { {:initiator => 'control'} }

context "with init_defaults" do
let(:arg2) { {:init_defaults => true} }
it "provisions a service template without errors" do
expect(resource_action_workflow).to receive(:validate_dialog).and_return([])
expect(resource_action_workflow).to receive(:make_request).and_return(miq_request)
expect(resource_action_workflow).to receive(:request_options=).with(
:init_defaults => true, :provision_workflow => true
)
expect(service_template.provision_request(user, arg1, arg2)).to eq(miq_request)
end
it "provisions a service template with errors" do
expect(resource_action_workflow).to receive(:validate_dialog).and_return(%w(Error1 Error2))
expect(resource_action_workflow).to receive(:request_options=).with(
:init_defaults => true, :provision_workflow => true
)
expect { service_template.provision_request(user, arg1, arg2) }.to raise_error(RuntimeError)
end
end

it "provisions a service template without errors" do
expect(resource_action_workflow).to receive(:validate_dialog).and_return([])
expect(resource_action_workflow).to receive(:make_request).and_return(miq_request)
Expand Down

0 comments on commit 5f1530c

Please sign in to comment.