Skip to content

Commit

Permalink
Add model changes
Browse files Browse the repository at this point in the history
  • Loading branch information
roshan-mathewtech committed Sep 30, 2022
2 parents 3a25fe7 + b727696 commit 8e3b608
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/models/cites_captivity_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class CitesCaptivityProcess < ActiveRecord::Base

# Change status field to Enum type after upgrading to rails 4.1
validates :status, presence: true, inclusion: {in: STATUS}
validate :start_event_value
validates :start_event, presence: true
validate :start_event_value, if: :is_start_event_present?
before_validation :set_resolution_value

def is_current?
status == 'Ongoing'
Expand All @@ -31,10 +33,18 @@ def start_date_formatted
end

private

def set_resolution_value
self.resolution = "Captive Breeding"
end

def start_event_value
unless ['CitesAc','CitesPc'].include? self.start_event.type
errors.add(:start_event, "is not valid")
end
end

def is_start_event_present?
start_event.present?
end
end

0 comments on commit 8e3b608

Please sign in to comment.