database_consistency 1.1.4 → 1.1.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c43909523b8cb7b8369f55dc151bf84e32752276907a249ada7606edffbbdca
|
4
|
+
data.tar.gz: b2a27e403ab36224ab3f432f4bd4d8021e75306c000b8fd20c01ea2cd868d795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7dac1b50e3e621c62f5bb00c96ef130bee3a862d70c3078dc29dd2538ca5f6a66f6772aa449ffed3771354a0514ab21e2b58df4b125dd62415f163b936667ee
|
7
|
+
data.tar.gz: f71af9349ed08f62b295c47cb32dc11a591a59cd44784e8f5ba00390c8011ccbc8597dc6cd63a5db4eee965f1ae0b758c8fa7487503c0f5469c27e492f7bfcd1
|
@@ -6,6 +6,8 @@ module DatabaseConsistency
|
|
6
6
|
class NullConstraintChecker < ColumnChecker
|
7
7
|
# Message templates
|
8
8
|
VALIDATOR_MISSING = 'column is required in the database but do not have presence validator'
|
9
|
+
ASSOCIATION_VALIDATOR_MISSING = 'column is required in the database but do '\
|
10
|
+
'not have presence validator for association (%a_n)'
|
9
11
|
|
10
12
|
private
|
11
13
|
|
@@ -26,21 +28,23 @@ module DatabaseConsistency
|
|
26
28
|
# | missing | fail |
|
27
29
|
#
|
28
30
|
# We consider PresenceValidation, InclusionValidation, ExclusionValidation, NumericalityValidator with nil,
|
29
|
-
# or BelongsTo association using this column
|
31
|
+
# or required BelongsTo association using this column
|
30
32
|
def check
|
31
33
|
if valid?
|
32
34
|
report_template(:ok)
|
35
|
+
elsif belongs_to_association
|
36
|
+
report_template(:fail, ASSOCIATION_VALIDATOR_MISSING.gsub('%a_n', belongs_to_association.name.to_s))
|
33
37
|
else
|
34
38
|
report_template(:fail, VALIDATOR_MISSING)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def valid?
|
39
|
-
validator?(
|
40
|
-
validator?(
|
43
|
+
validator?(:presence, column.name) ||
|
44
|
+
validator?(:inclusion, column.name) ||
|
41
45
|
numericality_validator_without_allow_nil? ||
|
42
46
|
nil_exclusion_validator? ||
|
43
|
-
belongs_to_association?
|
47
|
+
(belongs_to_association && validator?(:presence, belongs_to_association.name))
|
44
48
|
end
|
45
49
|
|
46
50
|
def primary_field?
|
@@ -52,28 +56,30 @@ module DatabaseConsistency
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def nil_exclusion_validator?
|
55
|
-
model.validators.
|
56
|
-
|
59
|
+
model.validators.any? do |validator|
|
60
|
+
validator.kind == :exclusion &&
|
61
|
+
Helper.check_inclusion?(validator.attributes, column.name) &&
|
57
62
|
validator.options[:in].include?(nil)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def numericality_validator_without_allow_nil?
|
62
|
-
model.validators.
|
63
|
-
|
67
|
+
model.validators.any? do |validator|
|
68
|
+
validator.kind == :numericality &&
|
69
|
+
Helper.check_inclusion?(validator.attributes, column.name) &&
|
64
70
|
!validator.options[:allow_nil]
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
68
|
-
def validator?(
|
69
|
-
model.validators.
|
70
|
-
Helper.check_inclusion?(validator.attributes,
|
74
|
+
def validator?(kind, attribute)
|
75
|
+
model.validators.any? do |validator|
|
76
|
+
validator.kind == kind && Helper.check_inclusion?(validator.attributes, attribute)
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
74
|
-
def belongs_to_association
|
75
|
-
model.reflect_on_all_associations.
|
76
|
-
Helper.check_inclusion?([r.foreign_key, r.foreign_type], column.name)
|
80
|
+
def belongs_to_association
|
81
|
+
@belongs_to_association ||= model.reflect_on_all_associations.find do |r|
|
82
|
+
r.belongs_to? && Helper.check_inclusion?([r.foreign_key, r.foreign_type], column.name)
|
77
83
|
end
|
78
84
|
end
|
79
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_consistency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|