Skip to content
Snippets Groups Projects
Commit 827e5a10 authored by Vijay Hawoldar's avatar Vijay Hawoldar
Browse files

Adds minimum value validation for plan limits

To help ensure expected values are used via the admin UI, we can
validate `PlanLimit` that  enforcement and notification limits
are greater than or equal to zero.

Changelog: changed
parent 2ac30178
No related branches found
No related tags found
1 merge request!122026Adds minimum value validation for plan limits
......@@ -9,8 +9,8 @@ class PlanLimits < ApplicationRecord
belongs_to :plan
validates :notification_limit, numericality: { only_integer: true }
validates :enforcement_limit, numericality: { only_integer: true }
validates :notification_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :enforcement_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
def exceeded?(limit_name, subject, alternate_limit: 0)
limit = limit_for(limit_name, alternate_limit: alternate_limit)
......
......@@ -13,8 +13,8 @@
end
describe 'validations' do
it { is_expected.to validate_numericality_of(:notification_limit).only_integer }
it { is_expected.to validate_numericality_of(:enforcement_limit).only_integer }
it { is_expected.to validate_numericality_of(:notification_limit).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:enforcement_limit).only_integer.is_greater_than_or_equal_to(0) }
end
describe '#exceeded?' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment