diff --git a/app/services/foreman_templates/parse_result.rb b/app/services/foreman_templates/parse_result.rb index 48721324..9280acf8 100644 --- a/app/services/foreman_templates/parse_result.rb +++ b/app/services/foreman_templates/parse_result.rb @@ -16,7 +16,7 @@ def to_h(verbose = false) :additional_errors => @additional_errors, :additional_info => @additional_info, :exception => @exception&.message, - :validation_errors => errors, + :validation_errors => transformed_errors, :file => @template_file, :type => @template.present? ? @template.class.name.underscore : nil } @@ -27,9 +27,7 @@ def to_h(verbose = false) end def errors - @template&.errors&.messages&.transform_values do |v| - v.join(', ') - end + @template&.errors end def corrupted_metadata @@ -99,5 +97,13 @@ def calculate_diff(old, new) nil end end + + private + + def transformed_errors + return {} unless errors + + errors.to_hash.transform_values(&:last) + end end end diff --git a/test/unit/template_importer_test.rb b/test/unit/template_importer_test.rb index daf8780c..18b0d551 100644 --- a/test/unit/template_importer_test.rb +++ b/test/unit/template_importer_test.rb @@ -222,15 +222,15 @@ def audit_comment template_res = find_result(results[:results], template.name) refute template_res.imported - assert_equal template_res.errors[:base], "This template is locked. Please clone it to a new template to customize." + assert_equal template_res.errors.full_messages.first, "This template is locked. Please clone it to a new template to customize." ptable_res = find_result(results[:results], ptable.name) refute ptable_res.imported - assert_equal ptable_res.errors[:base], "This template is locked. Please clone it to a new template to customize." + assert_equal ptable_res.errors.full_messages.first, "This template is locked. Please clone it to a new template to customize." snippet_res = find_result(results[:results], snippet.name) refute snippet_res.imported - assert_equal snippet_res.errors[:base], "This template is locked. Please clone it to a new template to customize." + assert_equal snippet_res.errors.full_messages.first, "This template is locked. Please clone it to a new template to customize." assert_equal @template_template, template.template assert_equal @ptable_layout, ptable.layout @@ -317,11 +317,11 @@ def keep_options_test_common(lock_setting) template_res = find_result(results[:results], template.name) refute template_res.imported - assert_equal template_res.errors[:base], "This template is locked. Please clone it to a new template to customize." + assert_equal template_res.errors.full_messages.first, "This template is locked. Please clone it to a new template to customize." ptable_res = find_result(results[:results], ptable.name) refute ptable_res.imported - assert_equal ptable_res.errors[:base], "This template is locked. Please clone it to a new template to customize." + assert_equal ptable_res.errors.full_messages.first, "This template is locked. Please clone it to a new template to customize." results end end