From 9cc4040308a758d4b77961f4da79cf63a044fffe Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 10 Jun 2024 11:23:55 -0400 Subject: [PATCH] Extract `COMMENT_SIZE_LIMIT` constant in `AP::Activity::Flag` class (#30637) --- app/lib/activitypub/activity/flag.rb | 4 +++- spec/lib/activitypub/activity/flag_spec.rb | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/lib/activitypub/activity/flag.rb b/app/lib/activitypub/activity/flag.rb index 68ee43d0eb..b7a412485c 100644 --- a/app/lib/activitypub/activity/flag.rb +++ b/app/lib/activitypub/activity/flag.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ActivityPub::Activity::Flag < ActivityPub::Activity + COMMENT_SIZE_LIMIT = 5000 + def perform return if skip_reports? @@ -38,6 +40,6 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity end def report_comment - (@json['content'] || '')[0...5000] + (@json['content'] || '')[0...COMMENT_SIZE_LIMIT] end end diff --git a/spec/lib/activitypub/activity/flag_spec.rb b/spec/lib/activitypub/activity/flag_spec.rb index 8593d567f4..426cd97df9 100644 --- a/spec/lib/activitypub/activity/flag_spec.rb +++ b/spec/lib/activitypub/activity/flag_spec.rb @@ -54,7 +54,7 @@ RSpec.describe ActivityPub::Activity::Flag do }.with_indifferent_access, sender) end - let(:long_comment) { Faker::Lorem.characters(number: 6000) } + let(:long_comment) { 'a' * described_class::COMMENT_SIZE_LIMIT * 2 } before do subject.perform @@ -63,10 +63,12 @@ RSpec.describe ActivityPub::Activity::Flag do it 'creates a report but with a truncated comment' do report = Report.find_by(account: sender, target_account: flagged) - expect(report).to_not be_nil - expect(report.comment.length).to eq 5000 - expect(report.comment).to eq long_comment[0...5000] - expect(report.status_ids).to eq [status.id] + expect(report) + .to be_present + .and have_attributes(status_ids: [status.id]) + expect(report.comment) + .to have_attributes(length: described_class::COMMENT_SIZE_LIMIT) + .and eq(long_comment[0...described_class::COMMENT_SIZE_LIMIT]) end end