From e301d4fdd37ab2f0ace7f9f40ce2735ced0fa929 Mon Sep 17 00:00:00 2001 From: Scott Venkataraman Date: Tue, 7 Apr 2026 14:45:46 -0400 Subject: [PATCH 1/6] Add exclusion pattern for bookmarks in reported_work_id of abuse_report.rb file --- app/models/abuse_report.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb index 7fa90f9e0cb..7f128cfc262 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 From 467337c6774c9c9103f51622a8f5c14738cab04a Mon Sep 17 00:00:00 2001 From: Scott Venkataraman Date: Mon, 20 Apr 2026 16:29:43 -0400 Subject: [PATCH 2/6] Add tests for abuse report --- spec/models/abuse_report_spec.rb | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index 0c3689d95e2..b07f09a4a3d 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 + allow(subject).to receive(:url).and_return("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 + allow(subject).to receive(:url).and_return("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 + allow(subject).to receive(:url).and_return("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 + allow(subject).to receive(:url).and_return("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 + allow(subject).to receive(:url).and_return("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/") From a823f0c3b235f30dc2336aa42b19d90a390faf3a Mon Sep 17 00:00:00 2001 From: Scott Venkataraman Date: Mon, 20 Apr 2026 16:36:19 -0400 Subject: [PATCH 3/6] Add trailing slash to bookmarks in abuse_report, update test to reflect change --- app/models/abuse_report.rb | 2 +- spec/models/abuse_report_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/abuse_report.rb b/app/models/abuse_report.rb index 7f128cfc262..f9c04cf151d 100644 --- a/app/models/abuse_report.rb +++ b/app/models/abuse_report.rb @@ -185,7 +185,7 @@ def creator_ids # 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] - bookmarks = url[%r{/bookmarks}, 0] + bookmarks = url[%r{/bookmarks/}, 0] url[%r{/works/(\d+)}, 1] if comments.nil? && bookmarks.nil? end diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index b07f09a4a3d..9c72dde065d 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -693,7 +693,7 @@ def queue_adapter_for_test context "for a work URL with bookmarks" do it "returns nil" do - allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/bookmarks") + allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/bookmarks/") expect(subject.reported_work_id).to be_nil end end From 6fb8b876320622cb6a91b8f5287ce8503a1505f7 Mon Sep 17 00:00:00 2001 From: Scott Venkataraman Date: Sat, 30 May 2026 11:50:13 -0400 Subject: [PATCH 4/6] Update tests to set field without mocks --- spec/models/abuse_report_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index 9c72dde065d..7786dfd57f9 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -672,35 +672,36 @@ def queue_adapter_for_test describe "#reported_work_id" do context "for a plain work URL" do it "returns the work id" do - allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/") + # allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/") + 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 - allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123#bookmark-form") + 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 - allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/comments/") + 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 - allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/bookmarks/") + subject.url = "http://archiveofourown.org/works/123/comments/" expect(subject.reported_work_id).to be_nil end end context "for a work URL with a specific bookmark" do it "returns nil" do - allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/bookmarks/456/") + subject.url = "http://archiveofourown.org/works/123/comments/" expect(subject.reported_work_id).to be_nil end end From c38b62279eafc132686b74553651021aad1ce3d9 Mon Sep 17 00:00:00 2001 From: Scott Venkataraman Date: Tue, 2 Jun 2026 16:58:06 -0400 Subject: [PATCH 5/6] Fixing copy paste errors --- spec/models/abuse_report_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index 7786dfd57f9..aee22c7e85e 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -672,7 +672,6 @@ def queue_adapter_for_test describe "#reported_work_id" do context "for a plain work URL" do it "returns the work id" do - # allow(subject).to receive(:url).and_return("http://archiveofourown.org/works/123/") subject.url = "http://archiveofourown.org/works/123/" expect(subject.reported_work_id).to eq("123") end @@ -694,14 +693,14 @@ def queue_adapter_for_test context "for a work URL with bookmarks" do it "returns nil" do - subject.url = "http://archiveofourown.org/works/123/comments/" + 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/comments/" + subject.url = "http://archiveofourown.org/works/123/bookmarks/456/" expect(subject.reported_work_id).to be_nil end end From b88545131d0a775fa9c18e4d68cca5a424619fcb Mon Sep 17 00:00:00 2001 From: Scott Venkataraman Date: Tue, 2 Jun 2026 18:14:43 -0400 Subject: [PATCH 6/6] Add trailing slash to url with bookmarks test --- spec/models/abuse_report_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index aee22c7e85e..bccf228ec5f 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -693,7 +693,7 @@ def queue_adapter_for_test context "for a work URL with bookmarks" do it "returns nil" do - subject.url = "http://archiveofourown.org/works/123/bookmarks" + subject.url = "http://archiveofourown.org/works/123/bookmarks/" expect(subject.reported_work_id).to be_nil end end