daily_affirmation 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a022e692ab6c6153908145526ce9b632fd7d5e0
|
4
|
+
data.tar.gz: a0c8602cf2068f7ce3ae72785311ba18ee39622a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d754e83e8cd50bebae51e08a48d0725f7d0e4cd9cf5176f2ee11830a0f17805800e083138ba6b9947170acecbbd10f0409f8596d6fe91a0df16319ef131b8906
|
7
|
+
data.tar.gz: 2065b6b3846a6511f4cbdbaf203b31f4189660ab11970385c15fc4d91ebf92486d936ad7fff57eb9baec6a94b9a6e54c905a49599e35ec10073ab661fc4494cc
|
@@ -4,7 +4,7 @@ module DailyAffirmation
|
|
4
4
|
module Validators
|
5
5
|
class NumericalityValidator < Validator
|
6
6
|
def valid?
|
7
|
-
@valid ||= numeric? && greater_than? && less_than?
|
7
|
+
@valid ||= value ? numeric? && greater_than? && less_than? : true
|
8
8
|
end
|
9
9
|
|
10
10
|
def error_message
|
@@ -16,23 +16,23 @@ module DailyAffirmation
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def numeric?
|
19
|
-
value.is_a?(Numeric)
|
19
|
+
@numeric ||= value.is_a?(Numeric)
|
20
20
|
end
|
21
21
|
|
22
22
|
def greater_than?
|
23
|
-
if gt = opts[:greater_than]
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
@greater_than ||= if numeric? && gt = opts[:greater_than]
|
24
|
+
value > gt
|
25
|
+
else
|
26
|
+
true
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def less_than?
|
31
|
-
if lt = opts[:less_than]
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
@less_than ||= if numeric? && lt = opts[:less_than]
|
32
|
+
value < lt
|
33
|
+
else
|
34
|
+
true
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def default_error_message
|
@@ -4,6 +4,13 @@ require_relative "../../lib/daily_affirmation/validators/numericality_validator"
|
|
4
4
|
describe "NumericalityValidator" do
|
5
5
|
subject { DailyAffirmation::Validators::NumericalityValidator }
|
6
6
|
|
7
|
+
it "passes validation if the arribute is nil" do
|
8
|
+
obj = double(:age => nil)
|
9
|
+
|
10
|
+
validator = subject.new(obj, :age)
|
11
|
+
expect(validator).to be_valid
|
12
|
+
end
|
13
|
+
|
7
14
|
it "passes validation if the attribute is a Numeric" do
|
8
15
|
obj = double(:age => 1.0)
|
9
16
|
|