Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ 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"
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_type = "fanwork-comment"
comment_post_modified_gmt = ultimate_parent.revised_at.iso8601
when ->(p) { p.is_a?(AdminPost) }
comment_type = "comment"
comment_post_modified_gmt = ultimate_parent.created_at.iso8601
end

if pseud_id.nil?
user_role = "guest"
Expand All @@ -126,7 +133,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?
Expand Down
26 changes: 26 additions & 0 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.iso8601)
expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.iso8601)
end
end
end
Comment on lines +296 to 304
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.


context "when the commentable is an admin post" do
Expand All @@ -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.iso8601)
end
end

context "when the commentable is a comment" do
Expand All @@ -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.iso8601)
expect(subject.akismet_attributes[:comment_post_modified_gmt]).not_to eq(work_posted_at.iso8601)
end
end
end

context "when the comment is on an admin post" do
Expand All @@ -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.iso8601)
end
end
end
end
Expand Down
Loading