DEV: add maxlength limits to chat messages and revisions (#23530)
Add additional limits to text columns for chat.
This commit is contained in:
parent
b7d7099d08
commit
16ccf30abc
|
@ -73,6 +73,7 @@ module Chat
|
|||
|
||||
before_save { ensure_last_editor_id }
|
||||
|
||||
validates :cooked, length: { maximum: 20_000 }
|
||||
validate :validate_message
|
||||
|
||||
def self.polymorphic_class_mapping = { "ChatMessage" => Chat::Message }
|
||||
|
|
|
@ -4,6 +4,9 @@ module Chat
|
|||
class MessageRevision < ActiveRecord::Base
|
||||
self.table_name = "chat_message_revisions"
|
||||
|
||||
validates :old_message, length: { maximum: 50_000 }
|
||||
validates :new_message, length: { maximum: 50_000 }
|
||||
|
||||
belongs_to :chat_message, class_name: "Chat::Message"
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Chat::MessageRevision do
|
||||
it { is_expected.to validate_length_of(:old_message).is_at_most(50_000) }
|
||||
it { is_expected.to validate_length_of(:new_message).is_at_most(50_000) }
|
||||
end
|
|
@ -7,6 +7,12 @@ describe Chat::Message do
|
|||
|
||||
it { is_expected.to have_many(:chat_mentions).dependent(:destroy) }
|
||||
|
||||
describe "validations" do
|
||||
subject(:message) { described_class.new(message: "") }
|
||||
|
||||
it { is_expected.to validate_length_of(:cooked).is_at_most(20_000) }
|
||||
end
|
||||
|
||||
describe ".cook" do
|
||||
it "does not support HTML tags" do
|
||||
cooked = described_class.cook("<h1>test</h1>")
|
||||
|
|
Loading…
Reference in New Issue