database_consistency 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/database_consistency/column_verifiers/presence_missing_verifier.rb +17 -3
- data/lib/database_consistency/database_processor.rb +1 -1
- data/lib/database_consistency/helper.rb +14 -2
- data/lib/database_consistency/report.rb +1 -1
- data/lib/database_consistency/version.rb +1 -1
- data/lib/database_consistency/writers/simple_writer.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93c3eb656f1f4ca77b34a647a612db82f713d624c672e7205a79ffc2c4715608
|
4
|
+
data.tar.gz: 879befe9d7b24ae68f1ef492b9f32ae1e166c9d32ff9706bc0aebd68007d0511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcb8edf4ae4fd959295dbdb1782c1f099c540b1c30d7d317da5f8164928502cd27666da9097059cbbfdc1f0ac060ed1ac90cab7aaf4cd6b2be683aad08c8010b
|
7
|
+
data.tar.gz: a3ee3f2e85349980cad0d06e273ba77c889e5bd262b17df3dfb2fda5440b3aac97acf4e69e9287f5ea98b7368535de882031aeef73a3f2c98f54dd5294ba8c20
|
@@ -5,7 +5,9 @@ module DatabaseConsistency
|
|
5
5
|
VALIDATOR_MISSING = 'is required but do not have presence validator'.freeze
|
6
6
|
|
7
7
|
def verify
|
8
|
-
|
8
|
+
return if skip? || presence_validator? || inclusion_validator? || belongs_to_reflection?
|
9
|
+
|
10
|
+
result(:fail, Helper.message(model, column, VALIDATOR_MISSING))
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
@@ -16,9 +18,21 @@ module DatabaseConsistency
|
|
16
18
|
(model.record_timestamps? && %w[created_at updated_at].include?(column.name))
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def presence_validator?
|
20
22
|
model.validators.grep(ActiveModel::Validations::PresenceValidator).any? do |validator|
|
21
|
-
|
23
|
+
Helper.check_inclusion?(validator.attributes, column.name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def inclusion_validator?
|
28
|
+
model.validators.grep(ActiveModel::Validations::InclusionValidator).any? do |validator|
|
29
|
+
Helper.check_inclusion?(validator.attributes, column.name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def belongs_to_reflection?
|
34
|
+
model.reflect_on_all_associations.grep(ActiveRecord::Reflection::BelongsToReflection).any? do |reflection|
|
35
|
+
Helper.check_inclusion?([reflection.foreign_key, reflection.foreign_type], column.name)
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
@@ -5,7 +5,14 @@ module DatabaseConsistency
|
|
5
5
|
|
6
6
|
# Returns list of models to check
|
7
7
|
def models
|
8
|
-
ActiveRecord::Base.descendants.
|
8
|
+
ActiveRecord::Base.descendants.delete_if(&:abstract_class?)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Return list of not inherited models
|
12
|
+
def parent_models
|
13
|
+
models.group_by(&:table_name).each_value.map do |models|
|
14
|
+
models.min_by { |model| models.include?(model.superclass) ? 1 : 0 }
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
# Loads all models
|
@@ -20,9 +27,14 @@ module DatabaseConsistency
|
|
20
27
|
|
21
28
|
# @return [String]
|
22
29
|
def message(model, column, template = nil)
|
23
|
-
str = "column #{column.name} of table #{model.table_name}"
|
30
|
+
str = "column #{column.name} of table #{model.table_name} of model #{model.name}"
|
24
31
|
str += " #{template}" if template
|
25
32
|
str
|
26
33
|
end
|
34
|
+
|
35
|
+
# @return [Boolean]
|
36
|
+
def check_inclusion?(array, element)
|
37
|
+
array.include?(element.to_s) || array.include?(element.to_sym)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
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: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Demin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|