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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e0c49605afc9e72f119e3d5ecb2809a556defc5ab84d52574eef569d8c08697
4
- data.tar.gz: 6a71e9bcb29d5e29c8cc4071fbab8ece22bb3ecbc1d814619c442782032d0924
3
+ metadata.gz: 234a7a00fa53a4b5ac5837c8a649ee0f3cf47c4fcf726f81b13fff07f88801b7
4
+ data.tar.gz: 322c24fb8cb5bd99838d45df843b0875d847c4251f0cc64ae12a99f9d0fdb82f
5
5
  SHA512:
6
- metadata.gz: 916dfe718138432512a974b258d5d6a9d86a46c184225889e41ebbcd2f13ec8989619f243b8a0ea05791fbcd87e88ad0ab328f4fda83090061275e0951f06fc2
7
- data.tar.gz: 7416170408b071fbc3eb6c448e4d604ae771dec9a67b7b37202405d5b36521e2b3c860a29f2b6c77c368af48d2cb235da4175d7bced7572c74730e6419bfd53b
6
+ metadata.gz: 6bc9da488a3da37d29bb96722d3925b5cb86f66dfc4de6d276fcea9bbdbd8285a5fdbe26ea9b23420d6c9966c7cc76ad950dde6d610a5d51d0924af8171a0648
7
+ data.tar.gz: 3cdbf12fca120344ca14b904030e0770af84f906e614a9c00ec8933e6272866c077f3feecce09be46403e521634e87ee33d5205f81b8f42d223095c5174c32ca
@@ -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.1...master
35
- [1.0.1]: https://gitlab.com/zedtux/nobrainer-rspec/-/compare/v1.0.0...v1.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
 
@@ -394,8 +394,18 @@ module NoBrainer
394
394
  end
395
395
 
396
396
  # Checking unique
397
- if @unique && (@klass.fields[attr][:unique] != @unique)
398
- error += ' unique'
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
- desc += ' to be unique' if @unique
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
@@ -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
@@ -32,6 +32,7 @@ module NoBrainer
32
32
 
33
33
  def check_scope
34
34
  message = " scope to #{@validator.options[:scope]}"
35
+
35
36
  if @validator.options[:scope]
36
37
  if [@validator.options[:scope] || ''].flatten.map(&:to_sym) == @scope
37
38
  @positive_result_message += message
@@ -2,6 +2,6 @@
2
2
 
3
3
  module NoBrainer
4
4
  module RSpec
5
- VERSION = '1.0.1'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  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.1
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-27 00:00:00.000000000 Z
11
+ date: 2020-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nobrainer