shoulda-matchers 4.1.2 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +168 -86
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +4 -2
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +3 -2
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +26 -21
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +16 -13
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +2 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -6
- data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +18 -16
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +31 -29
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -5
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +51 -25
- data/lib/shoulda/matchers/active_model/helpers.rb +1 -1
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -30
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +9 -1
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +9 -8
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +28 -46
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +33 -9
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +71 -26
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +31 -6
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +2 -4
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
- data/lib/shoulda/matchers/active_model/validator.rb +3 -3
- data/lib/shoulda/matchers/active_record.rb +26 -23
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +6 -3
- data/lib/shoulda/matchers/active_record/association_matcher.rb +100 -44
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +14 -15
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +30 -8
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +23 -5
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +8 -8
- data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +185 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +40 -18
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +106 -0
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +12 -10
- data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
- data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +30 -9
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +13 -9
- data/lib/shoulda/matchers/active_record/uniqueness.rb +1 -1
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +80 -73
- data/lib/shoulda/matchers/doublespeak.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
- data/lib/shoulda/matchers/doublespeak/object_double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
- data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
- data/lib/shoulda/matchers/error.rb +1 -1
- data/lib/shoulda/matchers/independent.rb +0 -1
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +14 -13
- data/lib/shoulda/matchers/integrations/configuration.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/rails_shim.rb +10 -21
- data/lib/shoulda/matchers/util.rb +16 -4
- data/lib/shoulda/matchers/util/word_wrap.rb +8 -8
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +3 -3
- data/shoulda-matchers.gemspec +10 -7
- metadata +11 -9
- data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +0 -37
@@ -31,12 +31,13 @@ module Shoulda
|
|
31
31
|
@key = key
|
32
32
|
end
|
33
33
|
|
34
|
-
def matches?(
|
34
|
+
def matches?(_controller)
|
35
35
|
filters_key?
|
36
36
|
end
|
37
37
|
|
38
38
|
def failure_message
|
39
|
-
"Expected #{@key} to be filtered; filtered keys:
|
39
|
+
"Expected #{@key} to be filtered; filtered keys:"\
|
40
|
+
" #{filtered_keys.join(', ')}"
|
40
41
|
end
|
41
42
|
|
42
43
|
def failure_message_when_negated
|
@@ -209,7 +209,8 @@ module Shoulda
|
|
209
209
|
attr_writer :stubbed_params
|
210
210
|
|
211
211
|
def initialize(expected_permitted_parameter_names)
|
212
|
-
@expected_permitted_parameter_names =
|
212
|
+
@expected_permitted_parameter_names =
|
213
|
+
expected_permitted_parameter_names
|
213
214
|
@action = nil
|
214
215
|
@verb = nil
|
215
216
|
@request_params = {}
|
@@ -262,18 +263,20 @@ module Shoulda
|
|
262
263
|
end
|
263
264
|
|
264
265
|
def failure_message
|
265
|
-
"Expected #{verb.upcase} ##{action} to #{expectation}
|
266
|
+
"Expected #{verb.upcase} ##{action} to #{expectation},"\
|
267
|
+
"\nbut #{reality}."
|
266
268
|
end
|
267
269
|
|
268
270
|
def failure_message_when_negated
|
269
|
-
"Expected #{verb.upcase} ##{action} not to #{expectation}
|
271
|
+
"Expected #{verb.upcase} ##{action} not to #{expectation},"\
|
272
|
+
"\nbut it did."
|
270
273
|
end
|
271
274
|
|
272
275
|
protected
|
273
276
|
|
274
|
-
attr_reader :controller, :double_collections_by_parameter_name, :action,
|
275
|
-
:
|
276
|
-
:parameters_double_registry
|
277
|
+
attr_reader :controller, :double_collections_by_parameter_name, :action,
|
278
|
+
:verb, :request_params, :expected_permitted_parameter_names,
|
279
|
+
:context, :subparameter_name, :parameters_double_registry
|
277
280
|
|
278
281
|
def expectation
|
279
282
|
message = 'restrict parameters '
|
@@ -282,7 +285,8 @@ module Shoulda
|
|
282
285
|
message << "on #{subparameter_name.inspect} "
|
283
286
|
end
|
284
287
|
|
285
|
-
message << 'to '
|
288
|
+
message << 'to '\
|
289
|
+
"#{format_parameter_names(expected_permitted_parameter_names)}"
|
286
290
|
|
287
291
|
message
|
288
292
|
end
|
@@ -291,9 +295,9 @@ module Shoulda
|
|
291
295
|
if actual_permitted_parameter_names.empty?
|
292
296
|
'it did not restrict any parameters'
|
293
297
|
else
|
294
|
-
'the restricted parameters were '
|
295
|
-
|
296
|
-
|
298
|
+
'the restricted parameters were '\
|
299
|
+
"#{format_parameter_names(actual_permitted_parameter_names)}"\
|
300
|
+
' instead'
|
297
301
|
end
|
298
302
|
end
|
299
303
|
|
@@ -303,12 +307,12 @@ module Shoulda
|
|
303
307
|
|
304
308
|
def actual_permitted_parameter_names
|
305
309
|
@_actual_permitted_parameter_names ||= begin
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
310
|
+
options =
|
311
|
+
if subparameter_name
|
312
|
+
{ for: subparameter_name }
|
313
|
+
else
|
314
|
+
{}
|
315
|
+
end
|
312
316
|
parameters_double_registry.permitted_parameter_names(options)
|
313
317
|
end
|
314
318
|
end
|
@@ -329,8 +333,8 @@ module Shoulda
|
|
329
333
|
|
330
334
|
def default_verb
|
331
335
|
case action
|
332
|
-
|
333
|
-
|
336
|
+
when :create then :post
|
337
|
+
when :update then RailsShim.verb_for_update
|
334
338
|
end
|
335
339
|
end
|
336
340
|
|
@@ -346,7 +350,7 @@ module Shoulda
|
|
346
350
|
|
347
351
|
def register
|
348
352
|
double_collection = Doublespeak.double_collection_for(
|
349
|
-
::ActionController::Parameters.singleton_class
|
353
|
+
::ActionController::Parameters.singleton_class,
|
350
354
|
)
|
351
355
|
double_collection.register_proxy(:new).to_return do |call|
|
352
356
|
params = call.return_value
|
@@ -389,7 +393,7 @@ module Shoulda
|
|
389
393
|
|
390
394
|
if double_collections_by_parameter_name.key?(subparameter_name)
|
391
395
|
self.class.permitted_parameter_names_within(
|
392
|
-
double_collections_by_parameter_name[subparameter_name]
|
396
|
+
double_collections_by_parameter_name[subparameter_name],
|
393
397
|
)
|
394
398
|
else
|
395
399
|
[]
|
@@ -436,7 +440,8 @@ module Shoulda
|
|
436
440
|
# @private
|
437
441
|
class VerbNotDefinedError < StandardError
|
438
442
|
def message
|
439
|
-
'You must specify an HTTP verb when using a non-RESTful action.
|
443
|
+
'You must specify an HTTP verb when using a non-RESTful action.'\
|
444
|
+
' For example: for(:authorize, verb: :post)'
|
440
445
|
end
|
441
446
|
end
|
442
447
|
end
|
@@ -75,14 +75,12 @@ module Shoulda
|
|
75
75
|
private
|
76
76
|
|
77
77
|
def redirects_to_url?
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
false
|
85
|
-
end
|
78
|
+
@context.__send__(:assert_redirected_to, url)
|
79
|
+
@failure_message_when_negated = "Didn't expect to redirect to #{url}"
|
80
|
+
true
|
81
|
+
rescue Shoulda::Matchers.assertion_exception_class => e
|
82
|
+
@failure_message = e.message
|
83
|
+
false
|
86
84
|
end
|
87
85
|
|
88
86
|
def url
|
@@ -71,14 +71,12 @@ module Shoulda
|
|
71
71
|
private
|
72
72
|
|
73
73
|
def renders_template?
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
false
|
81
|
-
end
|
74
|
+
@context.__send__(:assert_template, @options, @message)
|
75
|
+
@failure_message_when_negated = "Didn't expect to render #{@template}"
|
76
|
+
true
|
77
|
+
rescue Shoulda::Matchers.assertion_exception_class => e
|
78
|
+
@failure_message = e.message
|
79
|
+
false
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
@@ -64,12 +64,12 @@ module Shoulda
|
|
64
64
|
# @private
|
65
65
|
class RenderWithLayoutMatcher
|
66
66
|
def initialize(expected_layout)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
@expected_layout =
|
68
|
+
if expected_layout
|
69
|
+
expected_layout.to_s
|
70
|
+
else
|
71
|
+
nil
|
72
|
+
end
|
73
73
|
@controller = nil
|
74
74
|
end
|
75
75
|
|
@@ -95,11 +95,12 @@ module Shoulda
|
|
95
95
|
|
96
96
|
def description
|
97
97
|
description = 'render with '
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
description <<
|
99
|
+
if @expected_layout.nil?
|
100
|
+
'a layout'
|
101
|
+
else
|
102
|
+
"the #{@expected_layout.inspect} layout"
|
103
|
+
end
|
103
104
|
description
|
104
105
|
end
|
105
106
|
|
@@ -118,7 +119,9 @@ module Shoulda
|
|
118
119
|
end
|
119
120
|
|
120
121
|
def rendered_layouts
|
121
|
-
recorded_layouts.keys.compact.map { |layout|
|
122
|
+
recorded_layouts.keys.compact.map { |layout|
|
123
|
+
layout.sub(%r{^layouts/}, '')
|
124
|
+
}
|
122
125
|
end
|
123
126
|
|
124
127
|
def recorded_layouts
|
@@ -135,7 +138,7 @@ module Shoulda
|
|
135
138
|
|
136
139
|
def result
|
137
140
|
if rendered_with_layout?
|
138
|
-
|
141
|
+
"rendered with #{rendered_layouts.map(&:inspect).join(', ')}"
|
139
142
|
else
|
140
143
|
'rendered without a layout'
|
141
144
|
end
|
@@ -177,13 +177,12 @@ module Shoulda
|
|
177
177
|
|
178
178
|
def add_port_to_path(path, port)
|
179
179
|
if port
|
180
|
-
"
|
180
|
+
"https://example.com:#{port}" + path
|
181
181
|
else
|
182
182
|
path
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
|
187
186
|
def guess_controller_if_necessary(controller)
|
188
187
|
params[:controller] ||= controller.controller_path
|
189
188
|
end
|
@@ -195,11 +194,11 @@ module Shoulda
|
|
195
194
|
params,
|
196
195
|
)
|
197
196
|
true
|
198
|
-
rescue ::ActionController::RoutingError =>
|
199
|
-
@failure_message =
|
197
|
+
rescue ::ActionController::RoutingError => e
|
198
|
+
@failure_message = e.message
|
200
199
|
false
|
201
|
-
rescue Shoulda::Matchers.assertion_exception_class =>
|
202
|
-
@failure_message =
|
200
|
+
rescue Shoulda::Matchers.assertion_exception_class => e
|
201
|
+
@failure_message = e.message
|
203
202
|
false
|
204
203
|
end
|
205
204
|
end
|
@@ -20,7 +20,9 @@ module Shoulda
|
|
20
20
|
def to(expected_value = nil, &block)
|
21
21
|
if block
|
22
22
|
unless context_set?
|
23
|
-
message =
|
23
|
+
message = 'When specifying a value as a block, a context must be'\
|
24
|
+
' specified beforehand,'\
|
25
|
+
" e.g., #{store.name}.in_context(context).to { ... }"
|
24
26
|
raise ArgumentError, message
|
25
27
|
end
|
26
28
|
|
@@ -42,12 +44,14 @@ module Shoulda
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def failure_message
|
45
|
-
"Expected #{controller.class} to #{expectation_description},
|
47
|
+
"Expected #{controller.class} to #{expectation_description},"\
|
48
|
+
' but it did not'
|
46
49
|
end
|
47
50
|
alias_method :failure_message_for_should, :failure_message
|
48
51
|
|
49
52
|
def failure_message_when_negated
|
50
|
-
"Expected #{controller.class} not to #{expectation_description},
|
53
|
+
"Expected #{controller.class} not to #{expectation_description},"\
|
54
|
+
' but it did'
|
51
55
|
end
|
52
56
|
alias_method :failure_message_for_should_not,
|
53
57
|
:failure_message_when_negated
|
@@ -81,18 +85,20 @@ module Shoulda
|
|
81
85
|
def expectation_description
|
82
86
|
string = 'set'
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
string << " any key in #{store.name}"
|
88
|
-
end
|
89
|
-
|
90
|
-
if expected_value_set?
|
91
|
-
if expected_value.is_a?(Regexp)
|
92
|
-
string << " to a value matching #{expected_value.inspect}"
|
88
|
+
string <<
|
89
|
+
if key_set?
|
90
|
+
" #{store.name}[#{key.inspect}]"
|
93
91
|
else
|
94
|
-
|
92
|
+
" any key in #{store.name}"
|
95
93
|
end
|
94
|
+
|
95
|
+
if expected_value_set?
|
96
|
+
string <<
|
97
|
+
if expected_value.is_a?(Regexp)
|
98
|
+
" to a value matching #{expected_value.inspect}"
|
99
|
+
else
|
100
|
+
" to #{expected_value.inspect}"
|
101
|
+
end
|
96
102
|
end
|
97
103
|
|
98
104
|
string
|
@@ -89,23 +89,24 @@ module Shoulda
|
|
89
89
|
@subject = subject
|
90
90
|
if attr_mass_assignable?
|
91
91
|
if whitelisting?
|
92
|
-
@failure_message_when_negated = "#{@attribute} was made
|
92
|
+
@failure_message_when_negated = "#{@attribute} was made "\
|
93
|
+
'accessible'
|
94
|
+
elsif protected_attributes.empty?
|
95
|
+
@failure_message_when_negated = 'no attributes were protected'
|
93
96
|
else
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
"#{protected_attributes.to_a.to_sentence}, " <<
|
99
|
-
"but not #{@attribute}."
|
100
|
-
end
|
97
|
+
@failure_message_when_negated =
|
98
|
+
"#{class_name} is protecting " <<
|
99
|
+
"#{protected_attributes.to_a.to_sentence}, " <<
|
100
|
+
"but not #{@attribute}."
|
101
101
|
end
|
102
102
|
true
|
103
103
|
else
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
@failure_message =
|
105
|
+
if whitelisting?
|
106
|
+
"Expected #{@attribute} to be accessible"
|
107
|
+
else
|
108
|
+
"Did not expect #{@attribute} to be protected"
|
109
|
+
end
|
109
110
|
false
|
110
111
|
end
|
111
112
|
end
|
@@ -131,15 +132,16 @@ module Shoulda
|
|
131
132
|
end
|
132
133
|
|
133
134
|
def protected_attributes
|
134
|
-
@
|
135
|
+
@_protected_attributes ||= (@subject.class.protected_attributes || [])
|
135
136
|
end
|
136
137
|
|
137
138
|
def accessible_attributes
|
138
|
-
@
|
139
|
+
@_accessible_attributes ||=
|
140
|
+
(@subject.class.accessible_attributes || [])
|
139
141
|
end
|
140
142
|
|
141
143
|
def whitelisting?
|
142
|
-
authorizer.
|
144
|
+
authorizer.is_a?(::ActiveModel::MassAssignmentSecurity::WhiteList)
|
143
145
|
end
|
144
146
|
|
145
147
|
def attr_mass_assignable?
|
@@ -18,14 +18,14 @@ module Shoulda
|
|
18
18
|
#
|
19
19
|
# # RSpec
|
20
20
|
# RSpec.describe UserProfile, type: :model do
|
21
|
-
# it { should allow_value('
|
22
|
-
# it { should allow_value('
|
21
|
+
# it { should allow_value('https://foo.com').for(:website_url) }
|
22
|
+
# it { should allow_value('https://bar.com').for(:website_url) }
|
23
23
|
# end
|
24
24
|
#
|
25
25
|
# # Minitest (Shoulda)
|
26
26
|
# class UserProfileTest < ActiveSupport::TestCase
|
27
|
-
# should allow_value('
|
28
|
-
# should allow_value('
|
27
|
+
# should allow_value('https://foo.com').for(:website_url)
|
28
|
+
# should allow_value('https://bar.com').for(:website_url)
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
# You can also test multiple values in one go, if you like. In the
|
@@ -36,22 +36,22 @@ module Shoulda
|
|
36
36
|
# # RSpec
|
37
37
|
# RSpec.describe UserProfile, type: :model do
|
38
38
|
# it do
|
39
|
-
# should allow_values('
|
39
|
+
# should allow_values('https://foo.com', 'https://bar.com').
|
40
40
|
# for(:website_url)
|
41
41
|
# end
|
42
42
|
#
|
43
43
|
# it do
|
44
|
-
# should_not allow_values('
|
44
|
+
# should_not allow_values('foo', 'buz').
|
45
45
|
# for(:website_url)
|
46
46
|
# end
|
47
47
|
# end
|
48
48
|
#
|
49
49
|
# # Minitest (Shoulda)
|
50
50
|
# class UserProfileTest < ActiveSupport::TestCase
|
51
|
-
# should allow_values('
|
51
|
+
# should allow_values('https://foo.com', 'https://bar.com/baz').
|
52
52
|
# for(:website_url)
|
53
53
|
#
|
54
|
-
# should_not allow_values('
|
54
|
+
# should_not allow_values('foo', 'buz').
|
55
55
|
# for(:website_url)
|
56
56
|
# end
|
57
57
|
#
|
@@ -313,7 +313,7 @@ module Shoulda
|
|
313
313
|
:attribute_to_check_message_against,
|
314
314
|
:attribute_to_set,
|
315
315
|
:context,
|
316
|
-
:instance
|
316
|
+
:instance,
|
317
317
|
)
|
318
318
|
|
319
319
|
attr_writer(
|
@@ -423,55 +423,56 @@ module Shoulda
|
|
423
423
|
end
|
424
424
|
|
425
425
|
if include_attribute_changed_value_message?
|
426
|
-
message << "\n\n
|
426
|
+
message << "\n\n#{attribute_changed_value_message.call}"
|
427
427
|
end
|
428
428
|
|
429
429
|
Shoulda::Matchers.word_wrap(message)
|
430
430
|
end
|
431
431
|
|
432
|
-
def failure_message_when_negated
|
432
|
+
def failure_message_when_negated # rubocop:disable Metrics/MethodLength
|
433
433
|
attribute_setter = result.attribute_setter
|
434
434
|
|
435
435
|
if attribute_setter.unsuccessfully_checked?
|
436
436
|
message = attribute_setter.failure_message
|
437
437
|
else
|
438
438
|
validator = result.validator
|
439
|
-
message = failure_message_preface.call
|
439
|
+
message = "#{failure_message_preface.call} invalid"
|
440
440
|
|
441
441
|
if validator.type_of_message_matched?
|
442
442
|
if validator.has_messages?
|
443
443
|
message << ' and to'
|
444
444
|
|
445
|
-
if validator.captured_validation_exception?
|
445
|
+
if validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
|
446
446
|
message << ' raise a validation exception with message'
|
447
447
|
else
|
448
448
|
message << ' produce'
|
449
449
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
450
|
+
message <<
|
451
|
+
if expected_message.is_a?(Regexp) # rubocop:disable Metrics/BlockNesting
|
452
|
+
' a'
|
453
|
+
else
|
454
|
+
' the'
|
455
|
+
end
|
455
456
|
|
456
457
|
message << ' validation error'
|
457
458
|
end
|
458
459
|
|
459
|
-
if expected_message.is_a?(Regexp)
|
460
|
+
if expected_message.is_a?(Regexp) # rubocop:disable Metrics/BlockNesting
|
460
461
|
message << ' matching '
|
461
462
|
message << Shoulda::Matchers::Util.inspect_value(
|
462
|
-
expected_message
|
463
|
+
expected_message,
|
463
464
|
)
|
464
465
|
else
|
465
466
|
message << " #{expected_message.inspect}"
|
466
467
|
end
|
467
468
|
|
468
|
-
unless validator.captured_validation_exception?
|
469
|
+
unless validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
|
469
470
|
message << " on :#{attribute_to_check_message_against}"
|
470
471
|
end
|
471
472
|
|
472
473
|
message << '. The record was indeed invalid, but'
|
473
474
|
|
474
|
-
if validator.captured_validation_exception?
|
475
|
+
if validator.captured_validation_exception? # rubocop:disable Metrics/BlockNesting
|
475
476
|
message << ' the exception message was '
|
476
477
|
message << validator.validation_exception_message.inspect
|
477
478
|
message << ' instead.'
|
@@ -492,7 +493,7 @@ module Shoulda
|
|
492
493
|
end
|
493
494
|
|
494
495
|
if include_attribute_changed_value_message?
|
495
|
-
message << "\n\n
|
496
|
+
message << "\n\n#{attribute_changed_value_message.call}"
|
496
497
|
end
|
497
498
|
|
498
499
|
Shoulda::Matchers.word_wrap(message)
|
@@ -531,7 +532,8 @@ module Shoulda
|
|
531
532
|
|
532
533
|
def run(strategy)
|
533
534
|
attribute_setters_for_values_to_preset.first_failing ||
|
534
|
-
attribute_setters_and_validators_for_values_to_set.
|
535
|
+
attribute_setters_and_validators_for_values_to_set.
|
536
|
+
public_send(strategy)
|
535
537
|
end
|
536
538
|
|
537
539
|
def failure_message_preface
|
@@ -597,14 +599,14 @@ pass, or do something else entirely.
|
|
597
599
|
@_attribute_setters_and_validators_for_values_to_set ||=
|
598
600
|
AttributeSettersAndValidators.new(
|
599
601
|
self,
|
600
|
-
values_to_set.map { |value| [attribute_to_set, value] }
|
602
|
+
values_to_set.map { |value| [attribute_to_set, value] },
|
601
603
|
)
|
602
604
|
end
|
603
605
|
|
604
606
|
def inspected_values_to_set
|
605
607
|
Shoulda::Matchers::Util.inspect_values(values_to_set).to_sentence(
|
606
|
-
two_words_connector:
|
607
|
-
last_word_connector:
|
608
|
+
two_words_connector: ' or ',
|
609
|
+
last_word_connector: ', or ',
|
608
610
|
)
|
609
611
|
end
|
610
612
|
|
@@ -619,7 +621,7 @@ pass, or do something else entirely.
|
|
619
621
|
def default_attribute_message
|
620
622
|
default_error_message(
|
621
623
|
options[:expected_message],
|
622
|
-
default_attribute_message_values
|
624
|
+
default_attribute_message_values,
|
623
625
|
)
|
624
626
|
end
|
625
627
|
|
@@ -639,7 +641,7 @@ pass, or do something else entirely.
|
|
639
641
|
|
640
642
|
def human_attribute_name
|
641
643
|
instance.class.human_attribute_name(
|
642
|
-
attribute_to_check_message_against
|
644
|
+
attribute_to_check_message_against,
|
643
645
|
)
|
644
646
|
end
|
645
647
|
end
|