Skip to content

Conversation

@omerfaruk-pseud
Copy link
Member

@omerfaruk-pseud omerfaruk-pseud commented Dec 24, 2025

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-7238

Purpose

Adds the timestamp of modification of the parent which the comment was posted on (revision time for works and creation time for admin posts). It is to improve akismet's comment checks for better spam detection accuracy.

Credit

ömer faruk (he/him)

@sarken
Copy link
Collaborator

sarken commented Dec 24, 2025

I think tests similar to these tests of various akismet_attributes' values would be fine. Maybe we could use travel_to to make sure the work and chapter have different revised_at dates and the correct one gets used in the akismet_attribute?

Comment on lines 112 to 115
comment_post_modified_gmt = ultimate_parent.revised_at.to_i
else
comment_type = "comment"
comment_post_modified_gmt = ultimate_parent.created_at.to_i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Akismet wants the timestamp in ISO 8601 format

Copy link
Contributor

@marcus8448 marcus8448 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

# works or admin posts.
comment_type = ultimate_parent.is_a?(Work) ? "fanwork-comment" : "comment"
case ultimate_parent
when ->(p) { p.is_a?(Work) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
when ->(p) { p.is_a?(Work) }
when Work

Comment on lines +296 to 304
it "has comment_post_modified_gmt as the work's revision time", :frozen do
work_posted_at = Time.current
travel_to(1.day.from_now) do
Chapter.new work_id: subject.commentable.id
expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.iso8601)
expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.iso8601)
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this test isn't really checking what it looks like - subject is loaded lazily so the work is created within the time travel block. Chapter.new also doesn't automatically save the record, so the new chapter is never actually attached to the work (I believe we generally prefer to use factory bot's create which does save automatically).

I think it would be clearer (for all the tests) to compare directly to the records' revised_at/created_at time instead of freezing and comparing to now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants