Add validation limits for system notification fields

This commit is contained in:
Urban Rotnik 2019-02-20 16:05:15 +01:00
parent 35268252c8
commit 82ea31e275
3 changed files with 9 additions and 2 deletions

View file

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

View file

@ -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| "<p>#{pr}</p>" }.join }
source_created_at { Faker::Time.between(3.days.ago, Date.today) }

View file

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