Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/models/abuse_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions spec/models/abuse_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Comment thread
ScottVenkataraman marked this conversation as resolved.
Outdated
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/")
Expand Down
Loading