shoulda-matchers 4.1.1 → 4.1.2

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: f55ad44dc8280d7bb9598c809562c5d4b4bd174e78bdc8323898bdb7a3e8665a
4
- data.tar.gz: 80ddb4b8e6c0ab63c4b9225a1a75789d058d1e664c1b2248680469868072e724
3
+ metadata.gz: 686cc1117dd1671c3c3a6bed33c00f935dfc423eb74e640495b931965ba6ddbb
4
+ data.tar.gz: 0716b77fbb4bf86d7bc0b526a6d070081f753bff94af8bdd043415d3b71aa54d
5
5
  SHA512:
6
- metadata.gz: b912596ee8e4a25b1cbd98bca2878ac52cc19b54ab6014bbff0952b7449294e26a6d82b21a6d871b897eb23b26fb82bbc7b328d4de28bb73191fccf53e4e9c1b
7
- data.tar.gz: 168c002e0ed67d1a2dfde0465e2f48c2fcd4177810479f9c4d5970949f4fbec7db7cb5c71c33b7a341174d5c97fbbfb0782b18ada9f30695048bf25c64777875
6
+ metadata.gz: 35aeea48a5feeb86342ebaf93b8ae9621bd3255e12344c040e7c832f0a603073b7f7c95e4fd70029bc64c4daf49ca7bcd4193fc7b751d71c68e8ab1467503f18
7
+ data.tar.gz: d401a3db95f35d08b7cd1decc6adbea2acc338576ca48f233fe55ea9f6287535cbf7f6d0115a115931d69911e31c510d235bbc1689c98cf2d301dd65fcf6e52d
data/README.md CHANGED
@@ -19,7 +19,7 @@ complex, and error-prone.
19
19
 
20
20
  ## Quick links
21
21
 
22
- 📖 **[Read the documentation for the latest version (4.1.1)][rubydocs].**
22
+ 📖 **[Read the documentation for the latest version (4.1.2)][rubydocs].**
23
23
  📢 **[See what's changed in a recent version][news].**
24
24
 
25
25
  [rubydocs]: http://matchers.shoulda.io/docs
@@ -314,10 +314,11 @@ validation for you? Instead of using `validate_presence_of`, try
314
314
  def attribute_accepts_string_values?
315
315
  if association?
316
316
  false
317
- elsif attribute_serializer
318
- attribute_serializer.object_class == String
317
+ elsif attribute_serialization_coder.respond_to?(:object_class)
318
+ attribute_serialization_coder.object_class == String
319
319
  else
320
- attribute_type.try(:type) == :string
320
+ RailsShim.supports_full_attributes_api?(model) &&
321
+ attribute_type.try(:type) == :string
321
322
  end
322
323
  end
323
324
 
@@ -355,12 +356,8 @@ validation for you? Instead of using `validate_presence_of`, try
355
356
  end
356
357
  end
357
358
 
358
- def attribute_serializer
359
- if attribute_type.respond_to?(:coder)
360
- attribute_type.coder
361
- else
362
- nil
363
- end
359
+ def attribute_serialization_coder
360
+ RailsShim.attribute_serialization_coder_for(model, @attribute)
364
361
  end
365
362
 
366
363
  def attribute_type
@@ -183,15 +183,11 @@ module Shoulda
183
183
  end
184
184
 
185
185
  def attribute_is_serialized?
186
- serialized_attributes.include?(@name)
186
+ !!serialization_coder
187
187
  end
188
188
 
189
189
  def serialization_coder
190
- serialized_attributes[@name]
191
- end
192
-
193
- def serialized_attributes
194
- Shoulda::Matchers::RailsShim.serialized_attributes_for(model)
190
+ RailsShim.attribute_serialization_coder_for(model, @name)
195
191
  end
196
192
 
197
193
  def model
@@ -69,21 +69,20 @@ module Shoulda
69
69
  end
70
70
 
71
71
  def serialized_attributes_for(model)
72
- if defined?(::ActiveRecord::Type::Serialized)
73
- # Rails 5+
74
- serialized_columns = model.columns.select do |column|
75
- model.type_for_attribute(column.name).is_a?(
76
- ::ActiveRecord::Type::Serialized,
77
- )
72
+ attribute_types_for(model).
73
+ inject({}) do |hash, (attribute_name, attribute_type)|
74
+ if attribute_type.is_a?(::ActiveRecord::Type::Serialized)
75
+ hash.merge(attribute_name => attribute_type.coder)
76
+ else
77
+ hash
78
+ end
78
79
  end
80
+ rescue NotImplementedError
81
+ {}
82
+ end
79
83
 
80
- serialized_columns.inject({}) do |hash, column|
81
- hash[column.name.to_s] = model.type_for_attribute(column.name).coder
82
- hash
83
- end
84
- else
85
- model.serialized_attributes
86
- end
84
+ def attribute_serialization_coder_for(model, attribute_name)
85
+ serialized_attributes_for(model)[attribute_name.to_s]
87
86
  end
88
87
 
89
88
  def type_cast_default_for(model, column)
@@ -156,14 +155,35 @@ module Shoulda
156
155
  nil
157
156
  end
158
157
 
158
+ def attribute_types_for(model)
159
+ if model.respond_to?(:attribute_types)
160
+ model.attribute_types
161
+ elsif model.respond_to?(:type_for_attribute)
162
+ model.columns.inject({}) do |hash, column|
163
+ key = column.name.to_s
164
+ value = model.type_for_attribute(column.name)
165
+ hash.merge(key => value)
166
+ end
167
+ else
168
+ raise NotImplementedError
169
+ end
170
+ end
171
+
159
172
  def attribute_type_for(model, attribute_name)
160
- if supports_full_attributes_api?(model)
161
- model.attribute_types[attribute_name.to_s]
173
+ attribute_types_for(model)[attribute_name.to_s]
174
+ rescue NotImplementedError
175
+ if model.respond_to?(:type_for_attribute)
176
+ model.type_for_attribute(attribute_name)
162
177
  else
163
- LegacyAttributeType.new(model, attribute_name)
178
+ FakeAttributeType.new(model, attribute_name)
164
179
  end
165
180
  end
166
181
 
182
+ def supports_full_attributes_api?(model)
183
+ defined?(::ActiveModel::Attributes) &&
184
+ model.respond_to?(:attribute_types)
185
+ end
186
+
167
187
  private
168
188
 
169
189
  def simply_generate_validation_message(
@@ -188,23 +208,14 @@ module Shoulda
188
208
  I18n.translate(primary_translation_key, translate_options)
189
209
  end
190
210
 
191
- def supports_full_attributes_api?(model)
192
- defined?(::ActiveModel::Attributes) &&
193
- model.respond_to?(:attribute_types)
194
- end
195
-
196
- class LegacyAttributeType
211
+ class FakeAttributeType
197
212
  def initialize(model, attribute_name)
198
213
  @model = model
199
214
  @attribute_name = attribute_name
200
215
  end
201
216
 
202
217
  def coder
203
- if model.respond_to?(:serialized_attributes)
204
- ActiveSupport::Deprecation.silence do
205
- model.serialized_attributes[attribute_name.to_s]
206
- end
207
- end
218
+ nil
208
219
  end
209
220
 
210
221
  private
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '4.1.1'.freeze
4
+ VERSION = '4.1.2'.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: 4.1.1
4
+ version: 4.1.2
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: 2019-07-15 00:00:00.000000000 Z
17
+ date: 2019-07-31 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport