From e26a14dc298259ae6d7ae1f62921803c8a99371c Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 29 May 2018 12:21:47 -0400 Subject: [PATCH] FIX: error when flagging to notify moderators because message title is too long --- app/models/post_action.rb | 2 +- spec/models/post_action_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 3bab03db7b3..479091d8afc 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -245,7 +245,7 @@ SQL title = I18n.t("post_action_types.#{post_action_type}.email_title", title: post.topic.title, locale: SiteSetting.default_locale) body = I18n.t("post_action_types.#{post_action_type}.email_body", message: opts[:message], link: "#{Discourse.base_url}#{post.url}", locale: SiteSetting.default_locale) warning = opts[:is_warning] if opts[:is_warning].present? - title = title.truncate(255, separator: /\s/) + title = title.truncate(SiteSetting.max_topic_title_length, separator: /\s/) opts = { archetype: Archetype.private_message, diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index a8be0634a5a..e5e3544904f 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -619,6 +619,13 @@ describe PostAction do end end + it "should succeed even with low max title length" do + SiteSetting.max_topic_title_length = 50 + post.topic.title = 'This is a test topic ' * 2 + post.topic.save! + message_id = PostAction.create_message_for_post_action(Discourse.system_user, post, PostActionType.types[:notify_moderators], message: "WAT") + expect(message_id).to be_present + end end describe ".lookup_for" do