defra_ruby_validators 2.3.0 → 2.3.1

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: c9ba4d07bb3d5c11c1ab241e4121d64004a0e8c2
4
- data.tar.gz: 4b16fc9065a8d4072e55f4529d0ab04a9d905006
3
+ metadata.gz: 04bc1dd6e518b45824a7a10ac6e2c7c6d1013109
4
+ data.tar.gz: 1e98e3f97bafae4035294e95706db57a3374ef4d
5
5
  SHA512:
6
- metadata.gz: 91e943e088401c6c5345cc30c2a7710b65e09b01ae85cc97626a5f2959087ff1ee004cadaf137dd78a4c7a8d499b64e2c1972e2ae24a892c67cf68e95bdcc033
7
- data.tar.gz: 94c9eb588a7916a290e66dd9f1a2d628ffecde5db21c7ee55fd84b857a78f55088ab02935307f85ca5fd9679855fc00673f24b714e4636286115d2afefb374c6
6
+ metadata.gz: a19e32a494bf6865f35b067d7a6e650a5a568aa02f70944f1941e64142cb99ae9c5b4eeeabe7ec0d625005ee8c2e8147359e494e60f55e069a088e89e600fd52
7
+ data.tar.gz: fe26d0c04ecfbd11557b53a8b9c9969ff0e4efcdb5c075e4e6c118c6349d0632f8f04c544551c94e331d4148602125354d0681be063daf3eb60c9bfc6f8ec705
@@ -3,3 +3,4 @@ en:
3
3
  validators:
4
4
  PastDateValidator:
5
5
  past_date: "Date cannot be in the future"
6
+ invalid_date: "You must enter a valid date"
@@ -6,11 +6,21 @@ module DefraRuby
6
6
  def validate_each(record, attribute, value)
7
7
  return false if value.blank?
8
8
 
9
- return true if value.to_date <= Date.today
9
+ date = value.to_date
10
10
 
11
- record.errors[attribute] << error_message(:past_date)
11
+ if date > Date.today
12
+ record.errors[attribute] << error_message(:past_date)
12
13
 
13
- false
14
+ return false
15
+ end
16
+
17
+ if date.year < 1900
18
+ record.errors[attribute] << error_message(:invalid_date)
19
+
20
+ return false
21
+ end
22
+
23
+ true
14
24
  end
15
25
  end
16
26
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DefraRuby
4
4
  module Validators
5
- VERSION = "2.3.0"
5
+ VERSION = "2.3.1"
6
6
  end
7
7
  end
@@ -15,14 +15,21 @@ module DefraRuby
15
15
  RSpec.describe PastDateValidator, type: :model do
16
16
 
17
17
  valid_date = Date.today
18
- invalid_date = Date.today + 1
18
+ future_date = Date.today + 1
19
+ invalid_date = Date.new(20, 2, 2)
19
20
 
20
21
  it_behaves_like "a valid record", Test::PastDateValidatable.new(valid_date)
21
22
  it_behaves_like "an invalid record",
22
- validatable: Test::PastDateValidatable.new(invalid_date),
23
+ validatable: Test::PastDateValidatable.new(future_date),
23
24
  attribute: :date,
24
25
  error: :past_date,
25
26
  error_message: Helpers::Translator.error_message(PastDateValidator, :past_date)
27
+
28
+ it_behaves_like "an invalid record",
29
+ validatable: Test::PastDateValidatable.new(invalid_date),
30
+ attribute: :date,
31
+ error: :invalid_date,
32
+ error_message: Helpers::Translator.error_message(PastDateValidator, :invalid_date)
26
33
  end
27
34
  end
28
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-18 00:00:00.000000000 Z
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel