Commit 12b8516d authored by Sean Arnold's avatar Sean Arnold Committed by Stan Hu

Validate multiple polices only on create

parent a3c378f2
...@@ -7,7 +7,7 @@ module IncidentManagement ...@@ -7,7 +7,7 @@ module IncidentManagement
belongs_to :project belongs_to :project
has_many :rules, class_name: 'EscalationRule', inverse_of: :policy, foreign_key: 'policy_id', index_errors: true has_many :rules, class_name: 'EscalationRule', inverse_of: :policy, foreign_key: 'policy_id', index_errors: true
validates :project_id, uniqueness: { message: _('can only have one escalation policy') } validates :project_id, uniqueness: { message: _('can only have one escalation policy') }, on: :create
validates :name, presence: true, uniqueness: { scope: [:project_id] }, length: { maximum: 72 } validates :name, presence: true, uniqueness: { scope: [:project_id] }, length: { maximum: 72 }
validates :description, length: { maximum: 160 } validates :description, length: { maximum: 160 }
validates :rules, presence: true validates :rules, presence: true
......
...@@ -17,7 +17,7 @@ RSpec.describe IncidentManagement::EscalationPolicy do ...@@ -17,7 +17,7 @@ RSpec.describe IncidentManagement::EscalationPolicy do
describe 'validations' do describe 'validations' do
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:rules) } it { is_expected.to validate_presence_of(:rules) }
it { is_expected.to validate_uniqueness_of(:project_id).with_message(/can only have one escalation policy/) } it { is_expected.to validate_uniqueness_of(:project_id).with_message(/can only have one escalation policy/).on(:create) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) } it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
it { is_expected.to validate_length_of(:name).is_at_most(72) } it { is_expected.to validate_length_of(:name).is_at_most(72) }
it { is_expected.to validate_length_of(:description).is_at_most(160) } it { is_expected.to validate_length_of(:description).is_at_most(160) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment