parent
4f0360c7a2
commit
7b54990ae6
2 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue