diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 6ebf69ff6..986cf5105 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -20,9 +20,12 @@ class SystemNotification < ApplicationRecord :source_created_at, :source_id, :last_time_changed_at, presence: true - validates :title, :description, + validates :title, :description, :modal_title, length: { maximum: Constants::NAME_MAX_LENGTH } + validates :modal_body, + length: { maximum: Constants::RICH_TEXT_MAX_LENGTH } + def self.last_notifications( user, query = nil diff --git a/spec/factories/system_notifications.rb b/spec/factories/system_notifications.rb index 86e3c43e2..db2c23d14 100644 --- a/spec/factories/system_notifications.rb +++ b/spec/factories/system_notifications.rb @@ -3,7 +3,7 @@ FactoryBot.define do factory :system_notification do sequence(:title) { |n| "System notification #{n}" } - description { Faker::ChuckNorris.fact } + description { Faker::ChuckNorris.fact[0..255] } modal_title { Faker::Name.first_name } modal_body { Faker::Lorem.paragraphs(4).map { |pr| "
#{pr}
" }.join } source_created_at { Faker::Time.between(3.days.ago, Date.today) } diff --git a/spec/models/system_notification_spec.rb b/spec/models/system_notification_spec.rb index 4410812f6..db03fadf4 100644 --- a/spec/models/system_notification_spec.rb +++ b/spec/models/system_notification_spec.rb @@ -13,18 +13,22 @@ describe SystemNotification do describe 'Validations' do describe '#title' do it { is_expected.to validate_presence_of(:title) } + it { is_expected.to validate_length_of(:title).is_at_most(255) } end describe '#modal_title' do it { is_expected.to validate_presence_of(:modal_title) } + it { is_expected.to validate_length_of(:modal_title).is_at_most(255) } end describe '#modal_body' do it { is_expected.to validate_presence_of(:modal_body) } + it { is_expected.to validate_length_of(:modal_body).is_at_most(50000) } end describe '#description' do it { is_expected.to validate_presence_of(:description) } + it { is_expected.to validate_length_of(:description).is_at_most(255) } end describe '#source_id' do