nobrainer-rspec 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -2
- data/lib/matchers/have_field.rb +17 -3
- data/lib/matchers/validations.rb +23 -1
- data/lib/matchers/validations/uniqueness_of.rb +1 -0
- data/lib/nobrainer/rspec/version.rb +1 -1
- 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: 234a7a00fa53a4b5ac5837c8a649ee0f3cf47c4fcf726f81b13fff07f88801b7
|
4
|
+
data.tar.gz: 322c24fb8cb5bd99838d45df843b0875d847c4251f0cc64ae12a99f9d0fdb82f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc9da488a3da37d29bb96722d3925b5cb86f66dfc4de6d276fcea9bbdbd8285a5fdbe26ea9b23420d6c9966c7cc76ad950dde6d610a5d51d0924af8171a0648
|
7
|
+
data.tar.gz: 3cdbf12fca120344ca14b904030e0770af84f906e614a9c00ec8933e6272866c077f3feecce09be46403e521634e87ee33d5205f81b8f42d223095c5174c32ca
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ 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.0] - 2020-11-28
|
11
|
+
### Fixed
|
12
|
+
- have_field with a field using `unique: true` or `uniq: true`
|
13
|
+
|
9
14
|
## [1.0.1] - 2020-11-27
|
10
15
|
### Fixed
|
11
16
|
- Fixes gem build which was creating an empty gem
|
@@ -31,7 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
31
36
|
- validate_format_of
|
32
37
|
- validate_numericality_of
|
33
38
|
|
34
|
-
[Unreleased]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.0
|
35
|
-
[1.0
|
39
|
+
[Unreleased]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.1.0...master
|
40
|
+
[1.1.0]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.0.1...v1.1.0
|
41
|
+
[1.0.1]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.0.0...v1.0.1
|
36
42
|
[1.0.0]: https://gitlab.com/zedtux/nobrainer-rspec/-/tags/v1.0.0
|
37
43
|
|
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
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Hain
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nobrainer
|