Skip to content

Commit bb0ac25

Browse files
committed
presence validations on integer and float
1 parent edc44bc commit bb0ac25

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

app/models/float_field_type.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
class FloatFieldType < FieldType
22
attr_accessor :float
33

4-
validates_numericality_of :float
5-
validate :less_than, if: Proc.new { |int| validate_key(:max) }
6-
validate :greater_than, if: Proc.new { |int| validate_key(:min) }
4+
validates :float, presence: true, if: Proc.new { |float| validate_key(:presence) }
5+
validates_numericality_of :float, unless: "float.nil?"
6+
validate :less_than, if: Proc.new { |float| validate_key(:max) }
7+
validate :greater_than, if: Proc.new { |float| validate_key(:min) }
78

89
def data=(data_hash)
910
@float = data_hash.deep_symbolize_keys[:float]

app/models/integer_field_type.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
class IntegerFieldType < FieldType
22
attr_accessor :integer
33

4-
validates_numericality_of :integer
4+
validates :integer, presence: true, if: Proc.new { |int| validate_key(:presence) }
5+
validates_numericality_of :integer, unless: "integer.nil?"
56
validate :less_than, if: Proc.new { |int| validate_key(:max) }
67
validate :greater_than, if: Proc.new { |int| validate_key(:min) }
78

0 commit comments

Comments
 (0)