diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb index 7fa90f9e0cb..f9c04cf151d 100644 --- a/app/models/abuse_report.rb +++ b/app/models/abuse_report.rb @@ -182,10 +182,11 @@ def creator_ids end end - # ID of the reported work, unless the report is about comment(s) on the work + # ID of the reported work, unless the report is about comment(s) or bookmark(s) on the work def reported_work_id comments = url[%r{/comments/}, 0] - url[%r{/works/(\d+)}, 1] if comments.nil? + bookmarks = url[%r{/bookmarks/}, 0] + url[%r{/works/(\d+)}, 1] if comments.nil? && bookmarks.nil? end # ID of the reported comment diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index 0c3689d95e2..bccf228ec5f 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -669,6 +669,43 @@ def queue_adapter_for_test end end + describe "#reported_work_id" do + context "for a plain work URL" do + it "returns the work id" do + subject.url = "http://archiveofourown.org/works/123/" + expect(subject.reported_work_id).to eq("123") + end + end + + context "for a work URL with bookmark-form anchor" do + it "returns the work id" do + subject.url = "http://archiveofourown.org/works/123#bookmark-form" + expect(subject.reported_work_id).to eq("123") + end + end + + context "for a work URL with comments" do + it "returns nil" do + subject.url = "http://archiveofourown.org/works/123/comments/" + expect(subject.reported_work_id).to be_nil + end + end + + context "for a work URL with bookmarks" do + it "returns nil" do + subject.url = "http://archiveofourown.org/works/123/bookmarks/" + expect(subject.reported_work_id).to be_nil + end + end + + context "for a work URL with a specific bookmark" do + it "returns nil" do + subject.url = "http://archiveofourown.org/works/123/bookmarks/456/" + expect(subject.reported_work_id).to be_nil + end + end + end + describe "#creator_ids" do it "returns no creator ids for non-work URLs" do allow(subject).to receive(:url).and_return("http://archiveofourown.org/users/someone/")