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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 686cc1117dd1671c3c3a6bed33c00f935dfc423eb74e640495b931965ba6ddbb
|
4
|
+
data.tar.gz: 0716b77fbb4bf86d7bc0b526a6d070081f753bff94af8bdd043415d3b71aa54d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
318
|
-
|
317
|
+
elsif attribute_serialization_coder.respond_to?(:object_class)
|
318
|
+
attribute_serialization_coder.object_class == String
|
319
319
|
else
|
320
|
-
|
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
|
359
|
-
|
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
|
-
|
186
|
+
!!serialization_coder
|
187
187
|
end
|
188
188
|
|
189
189
|
def serialization_coder
|
190
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
161
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
17
|
+
date: 2019-07-31 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|