From c4cf8394da617bf12f40110d7b3a296e7c097521 Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Wed, 24 Dec 2025 11:28:14 +0300 Subject: [PATCH 1/9] AO3-7238 added comment_post_modified_gmt --- app/models/comment.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 9415aaa55e3..0dbb63e4a82 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -107,7 +107,13 @@ def akismet_attributes # While we do have tag comments, those are from logged-in users with special # access granted by admins, so we never spam check them, unlike comments on # works or admin posts. - comment_type = ultimate_parent.is_a?(Work) ? "fanwork-comment" : "comment" + if ultimate_parent.is_a?(Work) + comment_type = "fanwork-comment" + comment_post_modified_gmt = ultimate_parent.revised_at + else + comment_type = "comment" + comment_post_modified_gmt = ultimate_parent.created_at + end if pseud_id.nil? user_role = "guest" @@ -126,7 +132,8 @@ def akismet_attributes user_role: user_role, comment_author: comment_author, comment_author_email: comment_owner_email, - comment_content: comment_content + comment_content: comment_content, + comment_post_modified_gmt: comment_post_modified_gmt } attributes[:recheck_reason] = "edit" if will_save_change_to_edited_at? && will_save_change_to_comment_content? From 43a31179aaf24f9180f0d39df104ac3dfd159778 Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Wed, 24 Dec 2025 11:50:46 +0300 Subject: [PATCH 2/9] AO3-7238 add timestamp instead of rails obj --- app/models/comment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0dbb63e4a82..1e6fd1d90ef 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -109,10 +109,10 @@ def akismet_attributes # works or admin posts. if ultimate_parent.is_a?(Work) comment_type = "fanwork-comment" - comment_post_modified_gmt = ultimate_parent.revised_at + comment_post_modified_gmt = ultimate_parent.revised_at.to_i else comment_type = "comment" - comment_post_modified_gmt = ultimate_parent.created_at + comment_post_modified_gmt = ultimate_parent.created_at.to_i end if pseud_id.nil? From 0d149b50d3c3eced7da53ac5445487b1702da055 Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Wed, 24 Dec 2025 17:28:57 +0300 Subject: [PATCH 3/9] AO3-7238 not assign time and post type for tag comments --- app/models/comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 1e6fd1d90ef..0629380dec6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -110,7 +110,7 @@ def akismet_attributes if ultimate_parent.is_a?(Work) comment_type = "fanwork-comment" comment_post_modified_gmt = ultimate_parent.revised_at.to_i - else + elsif ultimate_parent.is_a?(AdminPost) comment_type = "comment" comment_post_modified_gmt = ultimate_parent.created_at.to_i end From 0bdfe67f5f8a5a3c9d5b6ca8384b35170e34f67e Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Thu, 25 Dec 2025 13:29:02 +0300 Subject: [PATCH 4/9] AO3-7238 add unit tests for values given to akismet --- spec/models/comment_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index d10be853ea6..9352af44936 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -292,6 +292,15 @@ def queue_adapter_for_test it "has comment_type \"fanwork-comment\"" do expect(subject.akismet_attributes[:comment_type]).to eq("fanwork-comment") end + + 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.to_i) + expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.to_i) + end + end end context "when the commentable is an admin post" do @@ -300,6 +309,10 @@ def queue_adapter_for_test it "has comment_type \"comment\"" do expect(subject.akismet_attributes[:comment_type]).to eq("comment") end + + it "has comment_post_modified_gmt as the admin post's creation time", :frozen do + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.to_i) + end end context "when the commentable is a comment" do @@ -309,6 +322,15 @@ def queue_adapter_for_test it "has comment_type \"fanwork-comment\"" do expect(subject.akismet_attributes[:comment_type]).to eq("fanwork-comment") end + + 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.commentable.id + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.to_i) + expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.to_i) + end + end end context "when the comment is on an admin post" do @@ -317,6 +339,10 @@ def queue_adapter_for_test it "has comment_type \"comment\"" do expect(subject.akismet_attributes[:comment_type]).to eq("comment") end + + it "has comment_post_modified_gmt as the admin post's creation time", :frozen do + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.to_i) + end end end end From 51010696b62ec29b6f9bc78ffb57dc51401a73a0 Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Thu, 25 Dec 2025 13:31:45 +0300 Subject: [PATCH 5/9] AO3-7238 use iso8601 instead of seconds for timestamp --- app/models/comment.rb | 4 ++-- spec/models/comment_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0629380dec6..75b68e93f1a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -109,10 +109,10 @@ def akismet_attributes # works or admin posts. if ultimate_parent.is_a?(Work) comment_type = "fanwork-comment" - comment_post_modified_gmt = ultimate_parent.revised_at.to_i + comment_post_modified_gmt = ultimate_parent.revised_at.iso8601 elsif ultimate_parent.is_a?(AdminPost) comment_type = "comment" - comment_post_modified_gmt = ultimate_parent.created_at.to_i + comment_post_modified_gmt = ultimate_parent.created_at.iso8601 end if pseud_id.nil? diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 9352af44936..97698587eec 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -297,8 +297,8 @@ def queue_adapter_for_test 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.to_i) - expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.to_i) + 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 @@ -311,7 +311,7 @@ def queue_adapter_for_test end it "has comment_post_modified_gmt as the admin post's creation time", :frozen do - expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.to_i) + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.iso8601) end end @@ -327,8 +327,8 @@ def queue_adapter_for_test work_posted_at = Time.current travel_to(1.day.from_now) do Chapter.new work_id: subject.commentable.commentable.id - expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.to_i) - expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.to_i) + 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 @@ -341,7 +341,7 @@ def queue_adapter_for_test end it "has comment_post_modified_gmt as the admin post's creation time", :frozen do - expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.to_i) + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.iso8601) end end end From 8f953ce25a439ba450d8819af98eef0032d4dbdc Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Thu, 25 Dec 2025 14:07:08 +0300 Subject: [PATCH 6/9] AO3-7238 convert if-elsif to case-when --- app/models/comment.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 75b68e93f1a..daa0feb0ac0 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -107,10 +107,11 @@ def akismet_attributes # While we do have tag comments, those are from logged-in users with special # access granted by admins, so we never spam check them, unlike comments on # works or admin posts. - if ultimate_parent.is_a?(Work) + case ultimate_parent + when ->(p) { p.is_a?(Work) } comment_type = "fanwork-comment" comment_post_modified_gmt = ultimate_parent.revised_at.iso8601 - elsif ultimate_parent.is_a?(AdminPost) + when ->(p) { p.is_a?(AdminPost) } comment_type = "comment" comment_post_modified_gmt = ultimate_parent.created_at.iso8601 end From 8b9195e066c7b8b40ac6fa52b88b8739e15a0e1a Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Fri, 9 Jan 2026 18:03:10 +0300 Subject: [PATCH 7/9] AO3-7238 shorten case when conditions --- app/models/comment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index daa0feb0ac0..da15453ef30 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -108,10 +108,10 @@ def akismet_attributes # access granted by admins, so we never spam check them, unlike comments on # works or admin posts. case ultimate_parent - when ->(p) { p.is_a?(Work) } + when Work comment_type = "fanwork-comment" comment_post_modified_gmt = ultimate_parent.revised_at.iso8601 - when ->(p) { p.is_a?(AdminPost) } + when AdminPost comment_type = "comment" comment_post_modified_gmt = ultimate_parent.created_at.iso8601 end From 6aa37023c86a33660a3fb38e18d3ecfb51023543 Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Fri, 9 Jan 2026 22:18:47 +0300 Subject: [PATCH 8/9] AO3-7238 make the tests clearer by using factorybot --- spec/models/comment_spec.rb | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 97698587eec..5242b09e8eb 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -293,13 +293,8 @@ def queue_adapter_for_test expect(subject.akismet_attributes[:comment_type]).to eq("fanwork-comment") end - 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 + it "has comment_post_modified_gmt as the work's revision time" do + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.revised_at.iso8601) end end @@ -310,8 +305,8 @@ def queue_adapter_for_test expect(subject.akismet_attributes[:comment_type]).to eq("comment") end - it "has comment_post_modified_gmt as the admin post's creation time", :frozen do - expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.iso8601) + it "has comment_post_modified_gmt as the admin post's creation time" do + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.created_at.iso8601) end end @@ -323,13 +318,8 @@ def queue_adapter_for_test expect(subject.akismet_attributes[:comment_type]).to eq("fanwork-comment") end - 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.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 + it "has comment_post_modified_gmt as the work's revision time" do + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.revised_at.iso8601) end end @@ -340,8 +330,8 @@ def queue_adapter_for_test expect(subject.akismet_attributes[:comment_type]).to eq("comment") end - it "has comment_post_modified_gmt as the admin post's creation time", :frozen do - expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(Time.current.iso8601) + it "has comment_post_modified_gmt as the admin post's creation time" do + expect(subject.akismet_attributes[:comment_post_modified_gmt]).to eq(subject.ultimate_parent.created_at.iso8601) end end end From 113b96ffacf2b3ade1c31b73c91c7a305aed8a15 Mon Sep 17 00:00:00 2001 From: omerfaruk-pseud Date: Fri, 9 Jan 2026 23:13:26 +0300 Subject: [PATCH 9/9] github ci is being weird