diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb index 61e6ad43a02..7c629dbb6b4 100755 --- a/app/controllers/works_controller.rb +++ b/app/controllers/works_controller.rb @@ -537,7 +537,12 @@ def import_multiple(urls, options) # collect the errors neatly, matching each error to the failed url unless failed_urls.empty? - error_msgs = 0.upto(failed_urls.length).map { |index| "
#{failed_urls[index]}
#{errors[index]}
" }.join("\n") + error_msgs = (0...failed_urls.length).map do |index| + # each failed url may have multiple errors, so show them in a bulleted list underneath the url + errors_per_url = errors[index].map { |error| "
  • #{error}
  • " } + .join("\n") + "
    #{failed_urls[index]}
    " + end.join("\n") flash.now[:error] = "

    #{ts('Failed Imports')}

    #{error_msgs}
    ".html_safe end diff --git a/app/models/story_parser.rb b/app/models/story_parser.rb index c9e869a21f5..536cb7a3bab 100644 --- a/app/models/story_parser.rb +++ b/app/models/story_parser.rb @@ -178,7 +178,7 @@ def import_from_urls(urls, options = {}) works << work else failed_urls << url - errors << work.errors.values.join(", ") + errors << work.errors.full_messages work.delete if work end rescue Timeout::Error diff --git a/spec/controllers/works/works_controller_spec.rb b/spec/controllers/works/works_controller_spec.rb index 2ab467ecd25..bfd3a6d0e26 100644 --- a/spec/controllers/works/works_controller_spec.rb +++ b/spec/controllers/works/works_controller_spec.rb @@ -24,4 +24,37 @@ end end end + + describe ".import_multiple" do + context "when the import has a failure from at least one URL" do + before do + allow_any_instance_of(StoryParser).to receive(:import_from_urls).and_return([ + [], + urls, + [["failedurl1 first error", "failedurl1 second error"], ["failedurl2 first error"]] + ]) + allow(controller).to receive(:render).with(:new_import) + end + let(:urls) { ["https://www.failedurl1.com", "https://www.failedurl2.com"] } + + it "returns a well-formatted error message" do + expect(controller).to receive(:render).with(:new_import) + controller.send(:import_multiple, urls, {}) + expect(flash[:error]).to eq( + "

    Failed Imports

    " \ + "
    " \ + "
    https://www.failedurl1.com
    " \ + "\n" \ + "
    https://www.failedurl2.com
    " \ + "" \ + "
    " + ) + end + end + end end