shoulda-matchers 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +11 -0
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +21 -3
- data/lib/shoulda/matchers/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: 188abbfbc6cac3e26997733b3d88b34ea74e9747e25f137738190bf15d033751
|
4
|
+
data.tar.gz: 73136b35573cffac784cadd7e3193e8e9a0934f0e69fa751f536ed589db01024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55f3ccad9ce3d4affcb6ccc38020872bc000710f887765d7b78962bcdd339d79a2a1316e3a9d2cb33c62887e66bab9e54801d79c872f6cab7a2459a32ddce4bf
|
7
|
+
data.tar.gz: e5a862e62f25dfe284f0325f20600bbc4a3567ef78a0b7742685d1a9af9d03147ab650a259be287bd4566719444c7d998c0106874b7c3ac43efbd79996191838
|
@@ -109,6 +109,8 @@ module Shoulda
|
|
109
109
|
end
|
110
110
|
elsif array_column?
|
111
111
|
['an arbitary value']
|
112
|
+
elsif enum_column?
|
113
|
+
enum_values.first
|
112
114
|
else
|
113
115
|
case column_type
|
114
116
|
when :integer, :float then 1
|
@@ -145,6 +147,15 @@ module Shoulda
|
|
145
147
|
@subject.class.columns_hash[@attribute.to_s].respond_to?(:array) &&
|
146
148
|
@subject.class.columns_hash[@attribute.to_s].array
|
147
149
|
end
|
150
|
+
|
151
|
+
def enum_column?
|
152
|
+
@subject.class.respond_to?(:defined_enums) &&
|
153
|
+
@subject.class.defined_enums.key?(@attribute.to_s)
|
154
|
+
end
|
155
|
+
|
156
|
+
def enum_values
|
157
|
+
@subject.class.defined_enums[@attribute.to_s].values
|
158
|
+
end
|
148
159
|
end
|
149
160
|
end
|
150
161
|
end
|
@@ -52,7 +52,7 @@ module Shoulda
|
|
52
52
|
#
|
53
53
|
# Use `with_options` to assert that a column has been defined with
|
54
54
|
# certain options (`:precision`, `:limit`, `:default`, `:null`, `:scale`,
|
55
|
-
# or `:
|
55
|
+
# `:primary` or `:array`).
|
56
56
|
#
|
57
57
|
# class CreatePhones < ActiveRecord::Migration
|
58
58
|
# def change
|
@@ -84,7 +84,7 @@ module Shoulda
|
|
84
84
|
|
85
85
|
# @private
|
86
86
|
class HaveDbColumnMatcher
|
87
|
-
OPTIONS = %i(precision limit default null scale primary).freeze
|
87
|
+
OPTIONS = %i(precision limit default null scale primary array).freeze
|
88
88
|
|
89
89
|
def initialize(column)
|
90
90
|
@column = column
|
@@ -115,7 +115,8 @@ module Shoulda
|
|
115
115
|
correct_default? &&
|
116
116
|
correct_null? &&
|
117
117
|
correct_scale? &&
|
118
|
-
correct_primary?
|
118
|
+
correct_primary? &&
|
119
|
+
correct_array?
|
119
120
|
end
|
120
121
|
|
121
122
|
def failure_message
|
@@ -258,6 +259,23 @@ module Shoulda
|
|
258
259
|
end
|
259
260
|
end
|
260
261
|
|
262
|
+
def correct_array?
|
263
|
+
return true unless @options.key?(:array)
|
264
|
+
|
265
|
+
if matched_column.array? == @options[:array]
|
266
|
+
true
|
267
|
+
else
|
268
|
+
@missing = "#{model_class} has a db column named #{@column} "
|
269
|
+
@missing <<
|
270
|
+
if @options[:primary]
|
271
|
+
'that is not array, but should be'
|
272
|
+
else
|
273
|
+
'that is array, but should not be'
|
274
|
+
end
|
275
|
+
false
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
261
279
|
def matched_column
|
262
280
|
@_matched_column ||= begin
|
263
281
|
column = model_class.columns.detect do |each|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tammer Saleh
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2021-
|
17
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
- !ruby/object:Gem::Version
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
|
-
rubygems_version: 3.2.
|
195
|
+
rubygems_version: 3.2.32
|
196
196
|
signing_key:
|
197
197
|
specification_version: 4
|
198
198
|
summary: Simple one-liner tests for common Rails functionality
|