diff options
| author | Robert Dober | 2017-10-16 09:27:27 +0200 |
|---|---|---|
| committer | GitHub | 2017-10-16 09:27:27 +0200 |
| commit | 072564dc48524f0bcc28d16051ec730ac1872e5e (patch) | |
| tree | 81f69b00184eb5d23f62d948384a5d78ab924547 /app/models | |
| parent | a8da41521f5e45d2ab39ddd9b0269d8cd1094d35 (diff) | |
| parent | d9ef8415e1da99db258a5181bff16b213f8c231a (diff) | |
| download | chouette-core-072564dc48524f0bcc28d16051ec730ac1872e5e.tar.bz2 | |
Merge pull request #93 from af83/4720-compliance-contorl-subclass-values
4720 compliance contorl subclass values
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/concerns/min_max_values_validation.rb | 13 | ||||
| -rw-r--r-- | app/models/generic_attribute_control/min_max.rb | 5 | ||||
| -rw-r--r-- | app/models/vehicle_journey_control/speed.rb | 1 |
3 files changed, 15 insertions, 4 deletions
diff --git a/app/models/concerns/min_max_values_validation.rb b/app/models/concerns/min_max_values_validation.rb new file mode 100644 index 000000000..c177e55ca --- /dev/null +++ b/app/models/concerns/min_max_values_validation.rb @@ -0,0 +1,13 @@ +module MinMaxValuesValidation + extend ActiveSupport::Concern + + included do + validate :min_max_values_validation + end + + def min_max_values_validation + return true unless minimum && maximum + return true unless maximum < minimum + errors.add(:min_max_values, I18n.t('compliance_controls.min_max_values', min: minimum, max: maximum)) + end +end diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb index c46ba0453..1f75c2edb 100644 --- a/app/models/generic_attribute_control/min_max.rb +++ b/app/models/generic_attribute_control/min_max.rb @@ -5,10 +5,7 @@ module GenericAttributeControl validates :minimum, numericality: true, allow_nil: true validates :maximum, numericality: true, allow_nil: true #validates :target, presence: true - validate :min_max_values - def min_max_values - true - end + include MinMaxValuesValidation class << self def attribute_type; :integer end diff --git a/app/models/vehicle_journey_control/speed.rb b/app/models/vehicle_journey_control/speed.rb index 099a46d1d..be9f838e4 100644 --- a/app/models/vehicle_journey_control/speed.rb +++ b/app/models/vehicle_journey_control/speed.rb @@ -4,6 +4,7 @@ module VehicleJourneyControl validates :minimum, numericality: true, allow_nil: true validates :maximum, numericality: true, allow_nil: true + include MinMaxValuesValidation def self.default_code; "3-VehicleJourney-2" end end |
