nobrainer-rspec 1.0.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -3
- data/Gemfile +1 -0
- data/lib/matchers/have_field.rb +17 -3
- data/lib/matchers/have_index_for.rb +2 -2
- data/lib/matchers/validations/uniqueness_of.rb +1 -0
- data/lib/matchers/validations.rb +23 -1
- data/lib/nobrainer/rspec/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a085f3d69d83e7deb6a1278c422ff1d0206884838aba9554567bb33947c2f2ec
|
4
|
+
data.tar.gz: 44c49d5de1198e404b47d724bc2d2763bee893067c50a53be3cf3a6076cfb124
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4abda54b105aec54fbf7f36aa3f99d0341a839edf270f1f9d499beed4b6115e4d7162208e53d84290ba31bec7dc4540a1f3d023f177ace45adae676efba15419
|
7
|
+
data.tar.gz: d6b1bb509c8376652546134665d442c70ac6dab87f2995db0b8f64ae4d2f68b56505b4d2cf9aab5fe734d47831259bacfab84cf133260175d72694c69bab8a52
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
|
10
|
+
## [1.1.2] - 2022-05-09
|
11
|
+
### Fixed
|
12
|
+
- have_index_for with a coupound index
|
13
|
+
|
14
|
+
## [1.1.1] - 2021-02-09
|
15
|
+
### Fixed
|
16
|
+
- error on generating failure description #1
|
17
|
+
|
18
|
+
## [1.1.0] - 2020-11-28
|
19
|
+
### Fixed
|
20
|
+
- have_field with a field using `unique: true` or `uniq: true`
|
21
|
+
|
9
22
|
## [1.0.1] - 2020-11-27
|
10
23
|
### Fixed
|
11
24
|
- Fixes gem build which was creating an empty gem
|
@@ -31,7 +44,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
31
44
|
- validate_format_of
|
32
45
|
- validate_numericality_of
|
33
46
|
|
34
|
-
[Unreleased]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.
|
35
|
-
[1.
|
47
|
+
[Unreleased]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.1.2...master
|
48
|
+
[1.1.2]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.1.1...v1.1.2
|
49
|
+
[1.1.1]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.1.0...v1.1.1
|
50
|
+
[1.1.0]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.0.1...v1.1.0
|
51
|
+
[1.0.1]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.0.0...v1.0.1
|
36
52
|
[1.0.0]: https://gitlab.com/zedtux/nobrainer-rspec/-/tags/v1.0.0
|
37
|
-
|
data/Gemfile
CHANGED
data/lib/matchers/have_field.rb
CHANGED
@@ -394,8 +394,18 @@ module NoBrainer
|
|
394
394
|
end
|
395
395
|
|
396
396
|
# Checking unique
|
397
|
-
if @unique
|
398
|
-
|
397
|
+
if @unique
|
398
|
+
uniq_key = @klass.fields[attr][:unique] ||
|
399
|
+
@klass.fields[attr][:uniq]
|
400
|
+
|
401
|
+
if @unique == true && uniq_key.nil?
|
402
|
+
error += ' unique'
|
403
|
+
end
|
404
|
+
|
405
|
+
if @unique.is_a?(Hash) && @unique.key?(:scope) &&
|
406
|
+
@unique[:scope] != uniq_key[:scope]
|
407
|
+
error += " unique scoped to #{uniq_key[:scope]}"
|
408
|
+
end
|
399
409
|
end
|
400
410
|
|
401
411
|
# Checking primary key
|
@@ -465,7 +475,11 @@ module NoBrainer
|
|
465
475
|
desc += ' allowing all values mentioned' if @allowed_values
|
466
476
|
desc += ' to be readonly' if @readonly
|
467
477
|
desc += ' to be lazy fetched' if @lazy_fetched
|
468
|
-
|
478
|
+
if @unique == true
|
479
|
+
desc += ' to be unique'
|
480
|
+
elsif @unique&.key?(:scope)
|
481
|
+
desc += " to be unique in the scope of #{@unique[:scope]}"
|
482
|
+
end
|
469
483
|
desc += ' as primary key' if @primary_key
|
470
484
|
desc += " with a length of #{@length}" if @length
|
471
485
|
desc += " with a minimal length of #{@min_length}" if @min_length
|
@@ -68,7 +68,7 @@ module NoBrainer
|
|
68
68
|
class HaveIndexFor # :nodoc:
|
69
69
|
def initialize(*attrs)
|
70
70
|
@attributes = attrs.collect do |attributes|
|
71
|
-
if attributes.is_a?(
|
71
|
+
if attributes.is_a?(Enumerable)
|
72
72
|
attributes.collect(&:to_sym)
|
73
73
|
else
|
74
74
|
attributes.to_sym
|
@@ -90,7 +90,7 @@ module NoBrainer
|
|
90
90
|
@klass = klass.is_a?(Class) ? klass : klass.class
|
91
91
|
@errors = []
|
92
92
|
@attributes.each do |attr|
|
93
|
-
if attr.is_a?(
|
93
|
+
if attr.is_a?(Enumerable)
|
94
94
|
missing_fields = attr - @klass.fields.keys
|
95
95
|
if missing_fields.empty?
|
96
96
|
index_key = @index_name || attr.join('_').to_sym
|
data/lib/matchers/validations.rb
CHANGED
@@ -25,7 +25,10 @@ module NoBrainer
|
|
25
25
|
return false
|
26
26
|
end
|
27
27
|
|
28
|
-
true
|
28
|
+
@result = true
|
29
|
+
check_on if @options[:on]
|
30
|
+
check_expected_message if @expected_message
|
31
|
+
@result
|
29
32
|
end
|
30
33
|
|
31
34
|
def failure_message_for_should
|
@@ -42,6 +45,7 @@ module NoBrainer
|
|
42
45
|
def description
|
43
46
|
desc = "have #{@type.inspect} validator on #{@field.inspect}"
|
44
47
|
desc += " on #{@options[:on]}" if @options[:on]
|
48
|
+
desc += " with message #{@expected_message.inspect}" if @expected_message
|
45
49
|
desc
|
46
50
|
end
|
47
51
|
|
@@ -50,6 +54,11 @@ module NoBrainer
|
|
50
54
|
self
|
51
55
|
end
|
52
56
|
|
57
|
+
def with_message(message)
|
58
|
+
@expected_message = message
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
53
62
|
private
|
54
63
|
|
55
64
|
def check_on
|
@@ -74,6 +83,19 @@ module NoBrainer
|
|
74
83
|
def on_options_covered_by?(validator)
|
75
84
|
([@options[:on]].flatten - [validator.options[:on]].flatten).empty?
|
76
85
|
end
|
86
|
+
|
87
|
+
def check_expected_message
|
88
|
+
actual_message = @validator.options[:message]
|
89
|
+
if actual_message.nil?
|
90
|
+
@negative_result_message << ' with no custom message'
|
91
|
+
@result = false
|
92
|
+
elsif actual_message == @expected_message
|
93
|
+
@positive_result_message << " with custom message '#{@expected_message}'"
|
94
|
+
else
|
95
|
+
@negative_result_message << " got message '#{actual_message}'"
|
96
|
+
@result = false
|
97
|
+
end
|
98
|
+
end
|
77
99
|
end
|
78
100
|
end
|
79
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nobrainer-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Hain
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nobrainer
|
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
|
-
rubygems_version: 3.1.
|
154
|
+
rubygems_version: 3.1.6
|
155
155
|
signing_key:
|
156
156
|
specification_version: 4
|
157
157
|
summary: RSpec matchers for Nobrainer
|