database_consistency 1.3.1 → 1.3.2

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: 9c6abf040aee5da4569c129d448c0b9dcc2344ace31f64ffad808f1f225f7328
4
- data.tar.gz: ccc59e66ac21cee7e6f71cf1d994dc65c09c5706343396af90af7a4b157a6ac8
3
+ metadata.gz: f0c1477361d612a93d643987fff549de519a50d8452b1019c04f32766598078a
4
+ data.tar.gz: 5132d1568f2573ef5a2bfdeb34321d29f8bc4938f2cc7fa3e75e383dec8a22d6
5
5
  SHA512:
6
- metadata.gz: 1617cef7111b2d5e3cca1f003176b1477b27529c1b433dc04a6131c1efff1b2ba8c1291637cd9fa4e169736c10807fa21b12f4c48197175596226d73814e64eb
7
- data.tar.gz: 87aa6bf2daaf34aec66256af9b999cc20e09587a71441b151e88a0616fba0c8c907e34ea4497b89c432538d8d0c59b78d27c8dda4f5222f3ca5ec6e759276951
6
+ metadata.gz: f3b9c74967fa7143dca1606de94d9ff18ed48553a1dc916a255f012e22f2509ead5ed943ec1b331fdac9bd11a41a5a0c5549948b9961ace82c374b17dfa9b064
7
+ data.tar.gz: 59cfde80772740f400642739011136f1292dc9c34540835f534f77cac7c2fe4a25d44dc279553b29ee93137dfb718815a08c07b663fd1e8c5fa949fa3003b0da
@@ -78,17 +78,23 @@ module DatabaseConsistency
78
78
  end
79
79
 
80
80
  def uniqueness_validator_columns(attribute, validator, model)
81
- ([wrapped_attribute_name(attribute, validator)] + scope_columns(validator, model)).map(&:to_s)
81
+ ([wrapped_attribute_name(attribute, validator, model)] + scope_columns(validator, model)).map(&:to_s)
82
82
  end
83
83
 
84
84
  def scope_columns(validator, model)
85
85
  Array.wrap(validator.options[:scope]).map do |scope_item|
86
- model._reflect_on_association(scope_item)&.foreign_key || scope_item
86
+ foreign_key_or_attribute(model, scope_item)
87
87
  end
88
88
  end
89
89
 
90
+ def foreign_key_or_attribute(model, attribute)
91
+ model._reflect_on_association(attribute)&.foreign_key || attribute
92
+ end
93
+
90
94
  # @return [String]
91
- def wrapped_attribute_name(attribute, validator)
95
+ def wrapped_attribute_name(attribute, validator, model)
96
+ attribute = foreign_key_or_attribute(model, attribute)
97
+
92
98
  if validator.options[:case_sensitive].nil? || validator.options[:case_sensitive]
93
99
  attribute
94
100
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseConsistency
4
- VERSION = '1.3.1'
4
+ VERSION = '1.3.2'
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.3.1
4
+ version: 1.3.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: 2022-11-07 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord