database_consistency 1.1.5 → 1.1.6

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
  SHA256:
3
- metadata.gz: 8c43909523b8cb7b8369f55dc151bf84e32752276907a249ada7606edffbbdca
4
- data.tar.gz: b2a27e403ab36224ab3f432f4bd4d8021e75306c000b8fd20c01ea2cd868d795
3
+ metadata.gz: 482d9a79d349bbe6d49233cf8ffb05accbf61c9d30db72b8e2d9c5d5517602a6
4
+ data.tar.gz: 14309f3ef7aab0e6aa0d20e4f9a0c0148a2be89e30d09235fb558cc55085d38d
5
5
  SHA512:
6
- metadata.gz: a7dac1b50e3e621c62f5bb00c96ef130bee3a862d70c3078dc29dd2538ca5f6a66f6772aa449ffed3771354a0514ab21e2b58df4b125dd62415f163b936667ee
7
- data.tar.gz: f71af9349ed08f62b295c47cb32dc11a591a59cd44784e8f5ba00390c8011ccbc8597dc6cd63a5db4eee965f1ae0b758c8fa7487503c0f5469c27e492f7bfcd1
6
+ metadata.gz: 7abe1d2b81e1f557b20da7c61a33c9fab8ebe709dd459e78ec16c4b088b3a457b094985428d72f882c6e946d028a444bfaf6aa1058764f03aef6bb54c2ecd89c
7
+ data.tar.gz: d2b930d6d7a0f639c9f7f139f207d90df85af5409d918d77cf7f3c781602844220996eb3fef6639f0c490f33235efa74f92817a254eb5ee4930ec429c4a4c02d
@@ -42,6 +42,8 @@ module DatabaseConsistency
42
42
  else
43
43
  report_template(:fail, render_text)
44
44
  end
45
+ rescue Errors::MissingField => e
46
+ report_template(:fail, e.message)
45
47
  end
46
48
 
47
49
  # @return [String]
@@ -101,8 +103,8 @@ module DatabaseConsistency
101
103
 
102
104
  # @return [String]
103
105
  def missing_field_error(table_name, column_name)
104
- "Association (#{association.name}) of class (#{association.active_record}) relies on "\
105
- "field (#{column_name}) of table (#{table_name}) but it is missing."
106
+ "association (#{association.name}) of class (#{association.active_record}) relies on "\
107
+ "field (#{column_name}) of table (#{table_name}) but it is missing"
106
108
  end
107
109
 
108
110
  # @param [ActiveRecord::ConnectionAdapters::Column] column
@@ -29,8 +29,18 @@ module DatabaseConsistency
29
29
  # | all missing | required | ok |
30
30
  # | all missing | optional | fail |
31
31
  def check
32
+ report_message
33
+ rescue Errors::MissingField => e
34
+ report_template(:fail, e.message)
35
+ end
36
+
37
+ def has_weak_option?
38
+ validators.all? { |validator| validator.options.slice(*WEAK_OPTIONS).any? }
39
+ end
40
+
41
+ def report_message
32
42
  can_be_null = column.null
33
- has_weak_option = validators.all? { |validator| validator.options.slice(*WEAK_OPTIONS).any? }
43
+ has_weak_option = has_weak_option?
34
44
 
35
45
  return report_template(:ok) if can_be_null == has_weak_option
36
46
  return report_template(:fail, POSSIBLE_NULL) unless can_be_null
@@ -44,7 +54,7 @@ module DatabaseConsistency
44
54
 
45
55
  def column
46
56
  @column ||= regular_column || association_reference_column ||
47
- (raise Errors::MissingField, "Missing column in #{model.table_name} for #{attribute}")
57
+ (raise Errors::MissingField, "column (#{attribute}) is missing in table (#{model.table_name}) but used for presence validation")
48
58
  end
49
59
 
50
60
  def regular_column
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.1.5'
4
+ VERSION = '1.1.6'
5
5
  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.5
4
+ version: 1.1.6
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-31 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord