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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 319b0cb3944a37309b11169bd71ffddde2d6af35b262795e7c16466d6d2c497c
4
- data.tar.gz: 22ac49d578766e24a18826bcde86443a09afa41c1cfc9ee7932f94f214623a36
3
+ metadata.gz: 188abbfbc6cac3e26997733b3d88b34ea74e9747e25f137738190bf15d033751
4
+ data.tar.gz: 73136b35573cffac784cadd7e3193e8e9a0934f0e69fa751f536ed589db01024
5
5
  SHA512:
6
- metadata.gz: 05a067ef5aa288661855f6257a55ce887bdf19f6684cd965c145669815a3d432a236cd7fb88e21647d0251e4e971b6c45b03af04def19b5cefbef26279276d81
7
- data.tar.gz: f06e9c331d39d82fd450332cb0b81e108852c7fac2a28927ada2fbccc11b31226206023f69eb6ecccd7dceaaca4c9b3410b818ed86babd3f7f37bb4c778013df
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
@@ -355,7 +355,7 @@ EOT
355
355
  description = "validate that :#{@attribute}"
356
356
 
357
357
  description <<
358
- if @array.many?
358
+ if @array.count > 1
359
359
  " is either #{inspected_array}"
360
360
  else
361
361
  " is #{inspected_array}"
@@ -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 `:primary`).
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|
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '5.0.0'.freeze
4
+ VERSION = '5.1.0'.freeze
5
5
  end
6
6
  end
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.0.0
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-07-10 00:00:00.000000000 Z
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.15
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