mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 11:45:18 +08:00
Merge pull request #1509 from urbanrotnik/ur-SCI-3060-SN-limits-for-fields
Add validation limits for system notification fields [SCI-3060]
This commit is contained in:
commit
f0933f4a89
3 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue