diff --git a/Gemfile.lock b/Gemfile.lock index e3eaa2d..a127c84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - proformaxml (1.3.0) + proformaxml (1.4.0) activemodel (>= 5.2.3, < 8.0.0) activesupport (>= 5.2.3, < 8.0.0) dachsfisch (~> 1.0.0) diff --git a/lib/proformaxml/services/importer.rb b/lib/proformaxml/services/importer.rb index 31bd929..47ffaa3 100644 --- a/lib/proformaxml/services/importer.rb +++ b/lib/proformaxml/services/importer.rb @@ -12,7 +12,7 @@ def initialize(zip:, expected_version: nil) @expected_version = expected_version xml = filestring_from_zip('task.xml') - raise PreImportValidationError if xml.nil? + raise PreImportValidationError.new(['no task_xml found']) if xml.blank? @doc = Nokogiri::XML(xml, &:noblanks) @task = Task.new @@ -28,8 +28,7 @@ def proforma_namespace def perform errors = validate - - raise PreImportValidationError.new(errors) if errors.any? + raise PreImportValidationError.new(errors.map(&:message)) if errors.any? @pro_ns = proforma_namespace @task_node = @doc.xpath("/#{@pro_ns}:task") diff --git a/lib/proformaxml/version.rb b/lib/proformaxml/version.rb index 3f693b1..2f1e73a 100644 --- a/lib/proformaxml/version.rb +++ b/lib/proformaxml/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ProformaXML - VERSION = '1.3.0' + VERSION = '1.4.0' end diff --git a/spec/proformaxml/importer_spec.rb b/spec/proformaxml/importer_spec.rb index 91d1674..1a18b26 100644 --- a/spec/proformaxml/importer_spec.rb +++ b/spec/proformaxml/importer_spec.rb @@ -37,6 +37,17 @@ expect(importer.instance_variable_get(:@expected_version)).to eql '2.0' end end + + context 'when zip-file does not contain task.xml' do + before do + zip_file.write('Foobar') + zip_file.rewind + end + + it 'raises correct error' do + expect { importer }.to raise_error(ProformaXML::PreImportValidationError, /no task_xml found/) + end + end end describe '#perform' do @@ -242,7 +253,7 @@ let(:export_version) { '2.1' } it 'raises an error' do - expect { perform }.to raise_error ProformaXML::PreImportValidationError + expect { perform }.to raise_error ProformaXML::PreImportValidationError, /No matching global declaration available for the validation root/ end end end