daily_affirmation 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4ecd8c16b9ba58d859435a2411832db38da7bba
4
- data.tar.gz: ae497ebd542784fadc5f2ebc55545cfd2efd1599
3
+ metadata.gz: 6a022e692ab6c6153908145526ce9b632fd7d5e0
4
+ data.tar.gz: a0c8602cf2068f7ce3ae72785311ba18ee39622a
5
5
  SHA512:
6
- metadata.gz: e2122846d1b00cc97b10f25a67f219306dd966813cd91610aed6af041f80b0c2faf8d2c6bf39564471bebf56caf4dc0821a5bdfd42140261d566e0b81564bce2
7
- data.tar.gz: 7875f55e1ca8cdefee943e2619d847ebe510c4b9e5fb2fffcf1120a462a3d65bb1949a0461494a1a252456eebda743f4caa40f1d9cb832549d3061a5f7496260
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
- value > gt
25
- else
26
- true
27
- end
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
- value < lt
33
- else
34
- true
35
- end
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
@@ -1,3 +1,3 @@
1
1
  module DailyAffirmation
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily_affirmation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons