From 0dcfd7ddeccd438fed97c15827214a3ddd944838 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Thu, 9 Feb 2023 17:44:04 +0400 Subject: [PATCH] =?UTF-8?q?DEV:=20correct=20a=20relationship=20=E2=80=93?= =?UTF-8?q?=20a=20chat=20message=20may=20have=20several=20mentions=20(#202?= =?UTF-8?q?19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change only makes the model reflect correctly what's already happening in the database. Note that there are no calls to chat_message.chat_mention in Core and plugins so this change should be safe. Also note, that at the moment we use the chat_mentions db table only to support notifications about mentions, but we're going to start using it for other cases. This commit is the first step in that direction. --- plugins/chat/app/models/chat_message.rb | 2 +- plugins/chat/spec/models/chat_message_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/chat/app/models/chat_message.rb b/plugins/chat/app/models/chat_message.rb index 2c07386bb3..e50afe6083 100644 --- a/plugins/chat/app/models/chat_message.rb +++ b/plugins/chat/app/models/chat_message.rb @@ -22,7 +22,7 @@ class ChatMessage < ActiveRecord::Base # TODO (martin) Remove this when we drop the ChatUpload table has_many :chat_uploads, dependent: :destroy has_one :chat_webhook_event, dependent: :destroy - has_one :chat_mention, dependent: :destroy + has_many :chat_mentions, dependent: :destroy scope :in_public_channel, -> { diff --git a/plugins/chat/spec/models/chat_message_spec.rb b/plugins/chat/spec/models/chat_message_spec.rb index 5f42e77f58..3633ace563 100644 --- a/plugins/chat/spec/models/chat_message_spec.rb +++ b/plugins/chat/spec/models/chat_message_spec.rb @@ -5,6 +5,8 @@ require "rails_helper" describe ChatMessage do fab!(:message) { Fabricate(:chat_message, message: "hey friend, what's up?!") } + it { is_expected.to have_many(:chat_mentions).dependent(:destroy) } + describe ".cook" do it "does not support HTML tags" do cooked = ChatMessage.cook("

test

")