database_validations 0.7.0 → 0.7.1
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: 4ee6d1beb244daa4a90b9336e202f68912a3e25b55085b2459ef8e4ffea161db
|
4
|
+
data.tar.gz: e266c1b54751162c0c589a2dea9fd450bfe1dde94271d91958b612b0d96282c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d98bb0b3d2b8810c60d5dabbfab6f4aa41619a1016c7d996394839822fcd61bcc2a9fbaf0c5b0502c88c76cc1cc39d16a4691b400d8dde679ce93d2bd1908a2
|
7
|
+
data.tar.gz: 7e7725c739b7e708e3736497a753c6aa2b446008d2070b82d6eed859e662513dac65f77bc96d264abd3cb329ef502856aa6b529dd6e825911bb24b1ec536b003
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# DatabaseValidations
|
2
2
|
|
3
3
|
[](https://travis-ci.org/toptal/database_validations)
|
4
|
+
[](https://badge.fury.io/rb/database_validations)
|
4
5
|
|
5
6
|
ActiveRecord provides validations on app level but it won't guarantee the
|
6
7
|
consistent. In some cases, like `validates_uniqueness_of` it executes
|
@@ -154,13 +155,13 @@ Example:
|
|
154
155
|
|
155
156
|
```ruby
|
156
157
|
class User < ActiveRecord::Base
|
157
|
-
validates_db_uniqueness_of :field, message: 'duplicate', where: '(some_field IS NULL)', scope: :another_field
|
158
|
+
validates_db_uniqueness_of :field, message: 'duplicate', where: '(some_field IS NULL)', scope: :another_field, index_name: :unique_index
|
158
159
|
end
|
159
160
|
|
160
161
|
describe 'validations' do
|
161
162
|
subject { User }
|
162
163
|
|
163
|
-
it { is_expected.to validate_db_uniqueness_of(:field).with_message('duplicate').with_where('(some_field IS NULL)').scoped_to(:another_field) }
|
164
|
+
it { is_expected.to validate_db_uniqueness_of(:field).with_message('duplicate').with_where('(some_field IS NULL)').scoped_to(:another_field).with_index(:unique_index) }
|
164
165
|
end
|
165
166
|
```
|
166
167
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# * `with_message(message)` -- specifies a message of the error;
|
7
7
|
# * `scoped_to(scope)` -- specifies a scope for the validator;
|
8
8
|
# * `with_where(where)` -- specifies a where condition for the validator;
|
9
|
+
# * `with_index(index_name)` -- specifies an index name for the validator;
|
9
10
|
#
|
10
11
|
# Example:
|
11
12
|
#
|
@@ -25,19 +26,24 @@ RSpec::Matchers.define :validate_db_uniqueness_of do |field|
|
|
25
26
|
@where = where
|
26
27
|
end
|
27
28
|
|
29
|
+
chain(:with_index) do |index_name|
|
30
|
+
@index_name = index_name
|
31
|
+
end
|
32
|
+
|
28
33
|
match do |model|
|
29
34
|
@validators = []
|
30
35
|
|
31
36
|
DatabaseValidations::Helpers.each_validator(model) do |validator|
|
32
37
|
@validators << {
|
33
|
-
field:
|
34
|
-
scope:
|
35
|
-
where:
|
36
|
-
message:
|
38
|
+
field: validator.field,
|
39
|
+
scope: validator.scope,
|
40
|
+
where: validator.where_clause,
|
41
|
+
message: validator.message,
|
42
|
+
index_name: validator.index_name
|
37
43
|
}
|
38
44
|
end
|
39
45
|
|
40
|
-
@validators.include?(field: field, scope: Array.wrap(@scope), where: @where, message: @message)
|
46
|
+
@validators.include?(field: field, scope: Array.wrap(@scope), where: @where, message: @message, index_name: @index_name)
|
41
47
|
end
|
42
48
|
|
43
49
|
description do
|
@@ -45,7 +51,8 @@ RSpec::Matchers.define :validate_db_uniqueness_of do |field|
|
|
45
51
|
desc += "With options - " if @message || @scope || @where
|
46
52
|
desc += "message: '#{@message}'; " if @message
|
47
53
|
desc += "scope: #{@scope}; " if @scope
|
48
|
-
desc += "where: '#{@where}'
|
54
|
+
desc += "where: '#{@where}'; " if @where
|
55
|
+
desc += "index_name: '#{index_name}'." if @index_name
|
49
56
|
desc
|
50
57
|
end
|
51
58
|
|
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
task :skip_db_uniqueness_validator_index_check do
|
5
|
-
ENV['SKIP_DB_UNIQUENESS_VALIDATOR_INDEX_CHECK'] = 'true'
|
6
|
-
end
|
7
|
-
end
|
1
|
+
namespace :database_validations do
|
2
|
+
task :skip_db_uniqueness_validator_index_check do
|
3
|
+
ENV['SKIP_DB_UNIQUENESS_VALIDATOR_INDEX_CHECK'] = 'true'
|
8
4
|
end
|
9
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
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-10-
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|