fix: Updated IMAP errors add method (#5520)

fixes: #5519
This commit is contained in:
Tejaswini Chile 2022-10-01 00:03:00 +05:30 committed by GitHub
parent 4f0360c7a2
commit 7b54990ae6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -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

View file

@ -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)) }