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

Fix dialog tag specs #23155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions app/models/service_orchestration/provision_tagging.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ServiceOrchestration::ProvisionTagging
DIALOG_TAG_KEY_REGEX = /^Array::dialog_tag_(?<sequence>\d*)_(?<option_key>.*)/i
DIALOG_TAG_KEY_REGEX = /^dialog_tag_(?<sequence>\d*)_(?<option_key>.*)/i
DIALOG_TAG_VALUE_REGEX = /Classification::(\d*)/

private
Expand All @@ -22,11 +22,15 @@ def provisioning_tag_ids
provision_sequence = miq_request_task.provision_priority + 1
dialog_options = root_service.options[:dialog] || {}

tags = []
dialog_options.flat_map do |key_name, value|
if (match = DIALOG_TAG_KEY_REGEX.match(key_name))
tag_sequence = match[:sequence].to_i
value.scan(DIALOG_TAG_VALUE_REGEX).flatten if tag_sequence.zero? || tag_sequence == provision_sequence
Array.wrap(value).each do |tag|
tags.push(tag.scan(DIALOG_TAG_VALUE_REGEX).flatten) if tag_sequence.zero? || tag_sequence == provision_sequence
end
end
end.compact
tags.flatten
end
end
4 changes: 2 additions & 2 deletions spec/models/dialog_field_tag_control_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ def add_entry(cat, options)
it "automate_output_value with an single value" do
tag = Classification.first
@df.value = tag.id.to_s
expect(@df.automate_output_value).to eq([tag.id.to_s])
expect(@df.automate_output_value).to eq(["#{tag.class.name}::#{tag.id}"])
end

it "automate_output_value with multiple values" do
tags = [Classification.first, Classification.last]
@df.value = tags.collect(&:id).join(",")
expect(@df.automate_output_value).to match_array(tags.collect { |tag| tag.id.to_s })
expect(@df.automate_output_value).to match_array(tags.collect { |tag| "#{tag.class.name}::#{tag.id}" })
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/models/service_orchestration/provision_tagging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
let(:service) { FactoryBot.build(:service_orchestration, :miq_request_task => miq_request_task) }
let(:dialog_tag_options) do
{:dialog => {
'Array::dialog_tag_0_env' => 'Classification::1',
'Array::dialog_tag_1_network' => 'Classification::11',
'Array::dialog_tag_2_dept' => 'Classification::21,Classification::22,Classification::23'
'dialog_tag_0_env' => ['Classification::1'],
'dialog_tag_1_network' => 'Classification::11,Classification::12', # Verify it works with both strings and arrays
'dialog_tag_2_dept' => ['Classification::21', 'Classification::22', 'Classification::23']
}}
end

Expand All @@ -42,7 +42,7 @@

context 'Calls Classification.bulk_reassignment with VM and tag IDs for provision_priority 0' do
let(:provision_priority) { 0 }
let(:tag_ids) { %w[1 11] }
let(:tag_ids) { %w[1 11 12] }

it_behaves_like 'service_orchestration VM tagging'
end
Expand All @@ -59,7 +59,7 @@

context 'Calls Classification.bulk_reassignment with VM and tag IDs for provision_priority 0' do
let(:provision_priority) { 0 }
let(:tag_ids) { %w[1 11] }
let(:tag_ids) { %w[1 11 12] }

it_behaves_like 'service_orchestration VM tagging'
end
Expand Down
Loading