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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04bc1dd6e518b45824a7a10ac6e2c7c6d1013109
|
4
|
+
data.tar.gz: 1e98e3f97bafae4035294e95706db57a3374ef4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a19e32a494bf6865f35b067d7a6e650a5a568aa02f70944f1941e64142cb99ae9c5b4eeeabe7ec0d625005ee8c2e8147359e494e60f55e069a088e89e600fd52
|
7
|
+
data.tar.gz: fe26d0c04ecfbd11557b53a8b9c9969ff0e4efcdb5c075e4e6c118c6349d0632f8f04c544551c94e331d4148602125354d0681be063daf3eb60c9bfc6f8ec705
|
@@ -6,11 +6,21 @@ module DefraRuby
|
|
6
6
|
def validate_each(record, attribute, value)
|
7
7
|
return false if value.blank?
|
8
8
|
|
9
|
-
|
9
|
+
date = value.to_date
|
10
10
|
|
11
|
-
|
11
|
+
if date > Date.today
|
12
|
+
record.errors[attribute] << error_message(:past_date)
|
12
13
|
|
13
|
-
|
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
|
@@ -15,14 +15,21 @@ module DefraRuby
|
|
15
15
|
RSpec.describe PastDateValidator, type: :model do
|
16
16
|
|
17
17
|
valid_date = Date.today
|
18
|
-
|
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(
|
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.
|
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-
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|