-
Notifications
You must be signed in to change notification settings - Fork 784
AO3-7414 Display error messages for multi-URL import #5792
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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| "<dt>#{failed_urls[index]}</dt><dd>#{errors[index]}</dd>" }.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| "<li>#{error}</li>" } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming by this point any content in the error messages (from validation, etc.) have been properly sanitized by |
||
| .join("\n") | ||
| "<dt>#{failed_urls[index]}</dt><ul>#{errors_per_url}</ul>" | ||
| end.join("\n") | ||
| flash.now[:error] = "<h3>#{ts('Failed Imports')}</h3><dl>#{error_msgs}</dl>".html_safe | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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( | ||
| "<h3>Failed Imports</h3>" \ | ||
| "<dl>" \ | ||
| "<dt>https://www.failedurl1.com</dt>" \ | ||
| "<ul>" \ | ||
| "<li>failedurl1 first error</li>\n" \ | ||
| "<li>failedurl1 second error</li>" \ | ||
| "</ul>\n" \ | ||
| "<dt>https://www.failedurl2.com</dt>" \ | ||
| "<ul>" \ | ||
| "<li>failedurl2 first error</li>" \ | ||
| "</ul>" \ | ||
| "</dl>" | ||
| ) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry this is a bit ugly! I wanted to test (1) that the |
||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.upto(failed_urls.length)includesfailed_urls.length, sofailed_url[index]was returningnilin the last iteration. Using...to make the range exclusive, but also happy to change it to0.upto(failed_urls.length - 1)if that reads better.