From 7b54990ae641ad8199239b76a06166d7c1e6230d Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Sat, 1 Oct 2022 00:03:00 +0530 Subject: [PATCH] fix: Updated IMAP errors add method (#5520) fixes: #5519 --- app/models/message.rb | 2 +- spec/models/message_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/message.rb b/app/models/message.rb index a2382ae3a..2930786f9 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -241,7 +241,7 @@ class Message < ApplicationRecord end def validate_attachments_limit(_attachment) - errors.add(attachments: 'exceeded maximum allowed') if attachments.size >= NUMBER_OF_PERMITTED_ATTACHMENTS + errors.add(:attachments, message: 'exceeded maximum allowed') if attachments.size >= NUMBER_OF_PERMITTED_ATTACHMENTS end def set_conversation_activity diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index e74a1129d..4940d704a 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -106,6 +106,19 @@ RSpec.describe Message, type: :model do end end + context 'when attachments size maximum' do + let(:message) { build(:message, content_type: nil, account: create(:account)) } + + it 'add errors to message for attachment size is more than allowed limit' do + 16.times.each do + attachment = message.attachments.new(account_id: message.account_id, file_type: :image) + attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + end + + expect(message.errors.messages).to eq({ attachments: ['exceeded maximum allowed'] }) + end + end + context 'when email notifiable message' do let(:message) { build(:message, content_type: nil, account: create(:account)) }