From 23a61310666c9ac5dcda3f0daf71592f665de028 Mon Sep 17 00:00:00 2001 From: Nat Date: Fri, 24 Jan 2025 12:20:11 +0800 Subject: [PATCH] Fix a rebase --- app/services/discourse_translator/base.rb | 5 +++-- spec/services/base_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/services/discourse_translator/base.rb b/app/services/discourse_translator/base.rb index a931925..ac78e99 100644 --- a/app/services/discourse_translator/base.rb +++ b/app/services/discourse_translator/base.rb @@ -79,8 +79,9 @@ def self.strip_tags_for_detection(detection_text) end def self.text_for_detection(topic_or_post) - strip_tags_for_detection( - get_text(topic_or_post).truncate(DETECTION_CHAR_LIMIT, omission: nil), + strip_tags_for_detection(get_text(topic_or_post)).truncate( + DETECTION_CHAR_LIMIT, + omission: nil, ) end diff --git a/spec/services/base_spec.rb b/spec/services/base_spec.rb index c1609d0..eb917c3 100644 --- a/spec/services/base_spec.rb +++ b/spec/services/base_spec.rb @@ -82,6 +82,11 @@ class EmptyTranslator < DiscourseTranslator::Base post.cooked = text expect(DiscourseTranslator::Base.text_for_detection(post)).to eq(text) end + + it "strips text before truncation" do + post.cooked = "" + "a" * 1000 + expect(DiscourseTranslator::Base.text_for_detection(post)).to eq("a" * 1000) + end end describe ".text_for_translation" do