Skip to content

Commit

Permalink
Merge pull request ManageIQ#255 from mkanoor/updated_spec_dialog_parser
Browse files Browse the repository at this point in the history
Updated spec dialog parser
  • Loading branch information
gmcculloug authored Mar 28, 2018
2 parents 06d74c6 + ee33464 commit dd599b7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ def process_comma_separated_object_array(sequence_id, option_key, value, hash)
return if value.nil?
options_value_array = []
value.split(",").each do |entry|
next if entry.blank?
vmdb_obj = vmdb_object_from_array_entry(entry)
next if vmdb_obj.nil?
options_value_array << (vmdb_obj.respond_to?(:name) ? vmdb_obj.name : "#{vmdb_obj.class.name}::#{vmdb_obj.id}")
options_value_array << if vmdb_obj.nil?
entry
else
(vmdb_obj.respond_to?(:name) ? vmdb_obj.name : "#{vmdb_obj.class.name}::#{vmdb_obj.id}")
end
end
hash[sequence_id][option_key] = options_value_array
end
Expand Down Expand Up @@ -75,13 +79,21 @@ def generic_dialog_value(dialog_key, dialog_value, options_hash)
true
end

def generic_dialog_array_value(dialog_key, dialog_value, options_hash)
return false unless /^array::(?<generic_dialog_key>dialog_(?<option_key>.*))/i =~ dialog_key
process_comma_separated_object_array(0, option_key.to_sym, dialog_value, options_hash)
process_comma_separated_object_array(0, generic_dialog_key.to_sym, dialog_value, options_hash)
true
end

def set_dialog_value(key, value, options_hash, tags_hash)
option_hash_value(key, value, options_hash) ||
option_array_value(key, value, options_hash) ||
option_password_value(key, value, options_hash) ||
tag_hash_value(key, value, tags_hash) ||
tag_array_value(key, value, tags_hash) ||
generic_dialog_value(key, value, options_hash) ||
generic_dialog_array_value(key, value, options_hash) ||
generic_password_value(key, value, options_hash)
end

Expand Down
23 changes: 20 additions & 3 deletions spec/automation/unit/method_validation/dialog_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def create_tags
@dept_array = Classification.find_by_description('Department').children.collect(&:name)
end

def create_vms
@vm_array_name = "Array::dialog_vm_array"
@vm_id_array = []
@vm_name_array = []
[FactoryGirl.create(:vm), FactoryGirl.create(:vm)].each do |vm|
@vm_id_array << "Vm::#{vm.id}"
@vm_name_array << vm.name
end
end

def setup_and_run_method(dialog_hash)
@root_stp.options = @root_stp.options.merge(:dialog => dialog_hash)
@root_stp.save
Expand All @@ -43,24 +53,31 @@ def load_tags

context "parser" do
it "with options tags and arrays" do
array_key = "Array::dialog_str_array"
array_value = %w(1 2 3)
create_tags
create_vms
dialog_hash = {'dialog_option_1_numero' => 'one', 'dialog_option_2_numero' => 'two',
'dialog_option_3_numero' => 'three', 'dialog_option_0_numero' => 'zero',
'dialog_tag_0_location' => 'NYC', 'dialog_tag_1_location' => 'BOM',
'dialog_tag_2_location' => 'EWR', @array_name => @dept_ids}
'dialog_tag_2_location' => 'EWR', @array_name => @dept_ids,
array_key => array_value.join(","),
@vm_array_name => @vm_id_array.join(",")}

parsed_dialog_options_hash = {1 => {:numero => "one"},
2 => {:numero => "two"},
3 => {:numero => "three"},
0 => {:numero => "zero"}}
0 => {:numero => "zero", :str_array => array_value,
:dialog_str_array => array_value,
:dialog_vm_array => @vm_name_array,
:vm_array => @vm_name_array}}
parsed_dialog_tags_hash = {0 => {:location => "NYC"},
1 => {:location => "BOM"},
2 => {:location => "EWR"}}

setup_and_run_method(dialog_hash)
pdo = load_options
pdt = load_tags

depts = pdt[0].delete(:department)
expect(pdo).to eql(parsed_dialog_options_hash)
expect(pdt).to eql(parsed_dialog_tags_hash)
Expand Down

0 comments on commit dd599b7

Please sign in to comment.