shoulda-matchers 3.0.0.rc1 → 3.0.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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/Gemfile.lock +12 -41
  4. data/NEWS.md +118 -26
  5. data/README.md +34 -11
  6. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -0
  7. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +4 -0
  8. data/gemfiles/4.0.0.gemfile +2 -3
  9. data/gemfiles/4.0.0.gemfile.lock +47 -77
  10. data/gemfiles/4.0.1.gemfile +2 -3
  11. data/gemfiles/4.0.1.gemfile.lock +51 -79
  12. data/gemfiles/4.1.gemfile +2 -3
  13. data/gemfiles/4.1.gemfile.lock +73 -103
  14. data/gemfiles/4.2.gemfile +2 -3
  15. data/gemfiles/4.2.gemfile.lock +90 -124
  16. data/lib/shoulda/matchers.rb +1 -0
  17. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +6 -8
  18. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +1 -3
  19. data/lib/shoulda/matchers/action_controller/flash_store.rb +1 -8
  20. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +140 -88
  21. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +2 -5
  22. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +5 -10
  23. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +2 -4
  24. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -3
  25. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -5
  26. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -7
  27. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +35 -9
  28. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
  29. data/lib/shoulda/matchers/active_model.rb +57 -1
  30. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +2 -5
  31. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +162 -54
  32. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -2
  33. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +1 -3
  34. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +24 -11
  35. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
  36. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +0 -2
  37. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
  38. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +2 -1
  39. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +15 -13
  40. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +3 -3
  41. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +3 -3
  42. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +4 -4
  43. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +8 -8
  44. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +8 -8
  45. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +12 -14
  46. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +10 -4
  47. data/lib/shoulda/matchers/active_model/validation_matcher.rb +0 -3
  48. data/lib/shoulda/matchers/active_model/validator.rb +0 -8
  49. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -6
  50. data/lib/shoulda/matchers/active_record/association_matcher.rb +58 -43
  51. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -2
  52. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +3 -5
  53. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +3 -5
  54. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +1 -4
  55. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -5
  56. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +7 -7
  57. data/lib/shoulda/matchers/doublespeak/double.rb +10 -1
  58. data/lib/shoulda/matchers/doublespeak/double_collection.rb +13 -5
  59. data/lib/shoulda/matchers/doublespeak/method_call.rb +10 -1
  60. data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
  61. data/lib/shoulda/matchers/doublespeak/world.rb +10 -0
  62. data/lib/shoulda/matchers/error.rb +4 -0
  63. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +11 -10
  64. data/lib/shoulda/matchers/integrations/libraries.rb +1 -0
  65. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
  66. data/lib/shoulda/matchers/integrations/libraries/active_model.rb +1 -1
  67. data/lib/shoulda/matchers/integrations/libraries/active_record.rb +1 -1
  68. data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -1
  69. data/lib/shoulda/matchers/integrations/libraries/routing.rb +27 -0
  70. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
  71. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
  72. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
  73. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
  74. data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +2 -2
  75. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
  76. data/lib/shoulda/matchers/routing.rb +10 -0
  77. data/lib/shoulda/matchers/version.rb +1 -1
  78. data/script/SUPPORTED_VERSIONS +1 -1
  79. data/spec/acceptance/independent_matchers_spec.rb +103 -42
  80. data/spec/doublespeak_spec_helper.rb +5 -1
  81. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +34 -11
  82. data/spec/support/acceptance/helpers/rspec_helpers.rb +9 -13
  83. data/spec/support/acceptance/helpers/step_helpers.rb +13 -0
  84. data/spec/support/acceptance/matchers/have_output.rb +1 -1
  85. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +1 -1
  86. data/spec/support/tests/command_runner.rb +5 -1
  87. data/spec/support/unit/helpers/active_record_versions.rb +0 -4
  88. data/spec/support/unit/shared_examples/set_session_or_flash.rb +8 -3
  89. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +198 -39
  90. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +269 -102
  91. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +24 -0
  92. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +118 -101
  93. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -82
  94. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +148 -121
  95. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +20 -8
  96. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +64 -183
  97. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +14 -0
  98. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +60 -0
  99. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +23 -7
  100. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +242 -0
  101. data/spec/unit_spec_helper.rb +4 -0
  102. data/tasks/documentation.rb +35 -0
  103. metadata +9 -8
  104. data/Guardfile +0 -5
  105. data/cucumber.yml +0 -1
  106. data/lib/shoulda/matchers/active_model/validator_with_captured_range_error.rb +0 -12
@@ -3,28 +3,28 @@ require 'unit_spec_helper'
3
3
  describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher, type: :model do
4
4
  context 'a model with an acceptance validation' do
5
5
  it 'accepts when the attributes match' do
6
- expect(validating_acceptance).to matcher
6
+ expect(record_validating_acceptance).to matcher
7
7
  end
8
8
 
9
9
  it 'does not overwrite the default message with nil' do
10
- expect(validating_acceptance).to matcher.with_message(nil)
10
+ expect(record_validating_acceptance).to matcher.with_message(nil)
11
11
  end
12
12
  end
13
13
 
14
14
  context 'a model without an acceptance validation' do
15
15
  it 'rejects' do
16
- expect(define_model(:example, attr: :string).new).not_to matcher
16
+ expect(record_validating_nothing).not_to matcher
17
17
  end
18
18
  end
19
19
 
20
20
  context 'an attribute which must be accepted with a custom message' do
21
21
  it 'accepts when the message matches' do
22
- expect(validating_acceptance(message: 'custom')).
22
+ expect(record_validating_acceptance(message: 'custom')).
23
23
  to matcher.with_message(/custom/)
24
24
  end
25
25
 
26
26
  it 'rejects when the message does not match' do
27
- expect(validating_acceptance(message: 'custom')).
27
+ expect(record_validating_acceptance(message: 'custom')).
28
28
  not_to matcher.with_message(/wrong/)
29
29
  end
30
30
  end
@@ -33,9 +33,21 @@ describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher, type: :mod
33
33
  validate_acceptance_of(:attr)
34
34
  end
35
35
 
36
- def validating_acceptance(options = {})
37
- define_model(:example, attr: :string) do
36
+ def model_validating_nothing(&block)
37
+ define_active_model_class(:example, accessors: [:attr], &block)
38
+ end
39
+
40
+ def record_validating_nothing
41
+ model_validating_nothing.new
42
+ end
43
+
44
+ def model_validating_acceptance(options = {})
45
+ model_validating_nothing do
38
46
  validates_acceptance_of :attr, options
39
- end.new
47
+ end
48
+ end
49
+
50
+ def record_validating_acceptance(options = {})
51
+ model_validating_acceptance(options).new
40
52
  end
41
53
  end
@@ -229,20 +229,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
229
229
  )
230
230
  expect(record).to validate_numericality.is_less_than_or_equal_to(18)
231
231
  end
232
-
233
- context 'if the given value is right at the allowed max value for the column' do
234
- it 'does not raise an error' do
235
- record = build_record_with_integer_column_of_limit(2,
236
- less_than_or_equal_to: 32767
237
- )
238
- assertion = lambda do
239
- expect(record).
240
- to validate_numericality.
241
- is_less_than_or_equal_to(32767)
242
- end
243
- expect(&assertion).not_to raise_error
244
- end
245
- end
246
232
  end
247
233
 
248
234
  context 'and not validating with less_than_or_equal_to' do
@@ -268,16 +254,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
268
254
  to validate_numericality.
269
255
  is_less_than(18)
270
256
  end
271
-
272
- context 'if the given value is right at the allowed max value for the column' do
273
- it 'does not raise an error' do
274
- record = build_record_with_integer_column_of_limit(2, less_than: 32767)
275
- assertion = lambda do
276
- expect(record).to validate_numericality.is_less_than(32767)
277
- end
278
- expect(&assertion).not_to raise_error
279
- end
280
- end
281
257
  end
282
258
 
283
259
  context 'and not validating with less_than' do
@@ -301,26 +277,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
301
277
  record = build_record_validating_numericality(equal_to: 18)
302
278
  expect(record).to validate_numericality.is_equal_to(18)
303
279
  end
304
-
305
- context 'if the given value is right at the allowed min value for the column' do
306
- it 'does not raise an error' do
307
- record = build_record_with_integer_column_of_limit(2, equal_to: -32768)
308
- assertion = lambda do
309
- expect(record).to validate_numericality.is_equal_to(-32768)
310
- end
311
- expect(&assertion).not_to raise_error
312
- end
313
- end
314
-
315
- context 'if the given value is right at the allowed max value for the column' do
316
- it 'does not raise an error' do
317
- record = build_record_with_integer_column_of_limit(2, equal_to: 32767)
318
- assertion = lambda do
319
- expect(record).to validate_numericality.is_equal_to(32767)
320
- end
321
- expect(&assertion).not_to raise_error
322
- end
323
- end
324
280
  end
325
281
 
326
282
  context 'and not validating with equal_to' do
@@ -346,20 +302,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
346
302
  to validate_numericality.
347
303
  is_greater_than_or_equal_to(18)
348
304
  end
349
-
350
- context 'if the given value is right at the allowed min value for the column' do
351
- it 'does not raise an error' do
352
- record = build_record_with_integer_column_of_limit(2,
353
- greater_than_or_equal_to: -32768
354
- )
355
- assertion = lambda do
356
- expect(record).
357
- to validate_numericality_of(:attr).
358
- is_greater_than_or_equal_to(-32768)
359
- end
360
- expect(&assertion).not_to raise_error
361
- end
362
- end
363
305
  end
364
306
 
365
307
  context 'not validating with greater_than_or_equal_to' do
@@ -385,20 +327,6 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
385
327
  to validate_numericality.
386
328
  is_greater_than(18)
387
329
  end
388
-
389
- context 'if the given value is right at the allowed min value for the column' do
390
- it 'does not raise an error' do
391
- record = build_record_with_integer_column_of_limit(2,
392
- greater_than: -32768
393
- )
394
- assertion = lambda do
395
- expect(record).
396
- to validate_numericality_of(:attr).
397
- is_greater_than(-32768)
398
- end
399
- expect(&assertion).not_to raise_error
400
- end
401
- end
402
330
  end
403
331
 
404
332
  context 'and not validating with greater_than' do
@@ -511,13 +439,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
511
439
  only_integer.
512
440
  is_greater_than(18)
513
441
  end
514
- message = format_message_according_to_rails_version(
515
- <<-MESSAGE.strip_heredoc
516
- Expected errors to include "must be an integer" when attr is set to 0.1,
517
- got errors:
518
- * "must be greater than 18" (attribute: attr, value: "0.1")
519
- MESSAGE
520
- )
442
+ message = <<-MESSAGE.strip_heredoc
443
+ Expected errors to include "must be an integer" when attr is set to "0.1",
444
+ got errors:
445
+ * "must be greater than 18" (attribute: attr, value: "0.1")
446
+ MESSAGE
521
447
  expect(&assertion).to fail_with_message(message)
522
448
  end
523
449
 
@@ -529,13 +455,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
529
455
  only_integer.
530
456
  is_greater_than(18)
531
457
  end
532
- message = format_message_according_to_rails_version(
533
- <<-MESSAGE.strip_heredoc
534
- Expected errors to include "must be an integer" when attr is set to 0.1,
535
- got errors:
536
- * "must be greater than 18" (attribute: attr, value: "0.1")
537
- MESSAGE
538
- )
458
+ message = <<-MESSAGE.strip_heredoc
459
+ Expected errors to include "must be an integer" when attr is set to "0.1",
460
+ got errors:
461
+ * "must be greater than 18" (attribute: attr, value: "0.1")
462
+ MESSAGE
539
463
  expect(&assertion).to fail_with_message(message)
540
464
  end
541
465
 
@@ -550,12 +474,10 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
550
474
  even.
551
475
  is_greater_than(18)
552
476
  end
553
- message = format_message_according_to_rails_version(
554
- <<-MESSAGE.strip_heredoc
555
- Expected errors to include "must be greater than 18" when attr is set to 18,
556
- got no errors
557
- MESSAGE
558
- )
477
+ message = <<-MESSAGE.strip_heredoc
478
+ Expected errors to include "must be greater than 18" when attr is set to "18",
479
+ got no errors
480
+ MESSAGE
559
481
  expect(&assertion).to fail_with_message(message)
560
482
  end
561
483
 
@@ -570,13 +492,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
570
492
  even.
571
493
  is_greater_than(18)
572
494
  end
573
- message = format_message_according_to_rails_version(
574
- <<-MESSAGE.strip_heredoc
575
- Expected errors to include "must be even" when attr is set to 1,
576
- got errors:
577
- * "must be greater than 18" (attribute: attr, value: "1")
578
- MESSAGE
579
- )
495
+ message = <<-MESSAGE.strip_heredoc
496
+ Expected errors to include "must be even" when attr is set to "1",
497
+ got errors:
498
+ * "must be greater than 18" (attribute: attr, value: "1")
499
+ MESSAGE
580
500
  expect(&assertion).to fail_with_message(message)
581
501
  end
582
502
 
@@ -591,12 +511,10 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
591
511
  odd.
592
512
  is_less_than_or_equal_to(99)
593
513
  end
594
- message = format_message_according_to_rails_version(
595
- <<-MESSAGE.strip_heredoc
596
- Expected errors to include "must be less than or equal to 99" when attr is set to 101,
597
- got no errors
598
- MESSAGE
599
- )
514
+ message = <<-MESSAGE.strip_heredoc
515
+ Expected errors to include "must be less than or equal to 99" when attr is set to "101",
516
+ got no errors
517
+ MESSAGE
600
518
  expect(&assertion).to fail_with_message(message)
601
519
  end
602
520
 
@@ -613,12 +531,10 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
613
531
  is_greater_than(18).
614
532
  is_less_than(99)
615
533
  end
616
- message = format_message_according_to_rails_version(
617
- <<-MESSAGE.strip_heredoc
618
- Expected errors to include "must be greater than 18" when attr is set to 18,
619
- got no errors
620
- MESSAGE
621
- )
534
+ message = <<-MESSAGE.strip_heredoc
535
+ Expected errors to include "must be greater than 18" when attr is set to "18",
536
+ got no errors
537
+ MESSAGE
622
538
  expect(&assertion).to fail_with_message(message)
623
539
  end
624
540
  end
@@ -635,13 +551,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
635
551
  only_integer.
636
552
  is_greater_than(18)
637
553
  end
638
- message = format_message_according_to_rails_version(
639
- <<-MESSAGE.strip_heredoc
640
- Expected errors to include "must be greater than 18" when attr is set to 18,
641
- got errors:
642
- * "must be greater than 19" (attribute: attr, value: "19")
643
- MESSAGE
644
- )
554
+ message = <<-MESSAGE.strip_heredoc
555
+ Expected errors to include "must be greater than 18" when attr is set to "18",
556
+ got errors:
557
+ * "must be greater than 19" (attribute: attr, value: "19")
558
+ MESSAGE
645
559
  expect(&assertion).to fail_with_message(message)
646
560
  end
647
561
 
@@ -656,12 +570,10 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
656
570
  only_integer.
657
571
  is_greater_than(18)
658
572
  end
659
- message = format_message_according_to_rails_version(
660
- <<-MESSAGE.strip_heredoc
661
- Expected errors to include "must be greater than 18" when attr is set to 18,
662
- got no errors
663
- MESSAGE
664
- )
573
+ message = <<-MESSAGE.strip_heredoc
574
+ Expected errors to include "must be greater than 18" when attr is set to "18",
575
+ got no errors
576
+ MESSAGE
665
577
  expect(&assertion).to fail_with_message(message)
666
578
  end
667
579
 
@@ -676,13 +588,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
676
588
  even.
677
589
  is_greater_than(18)
678
590
  end
679
- message = format_message_according_to_rails_version(
680
- <<-MESSAGE.strip_heredoc
681
- Expected errors to include "must be greater than 18" when attr is set to 18,
682
- got errors:
683
- * "must be greater than 20" (attribute: attr, value: "20")
684
- MESSAGE
685
- )
591
+ message = <<-MESSAGE.strip_heredoc
592
+ Expected errors to include "must be greater than 18" when attr is set to "18",
593
+ got errors:
594
+ * "must be greater than 20" (attribute: attr, value: "20")
595
+ MESSAGE
686
596
  expect(&assertion).to fail_with_message(message)
687
597
  end
688
598
 
@@ -697,12 +607,10 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
697
607
  even.
698
608
  is_greater_than(18)
699
609
  end
700
- message = format_message_according_to_rails_version(
701
- <<-MESSAGE.strip_heredoc
702
- Expected errors to include "must be greater than 18" when attr is set to 18,
703
- got no errors
704
- MESSAGE
705
- )
610
+ message = <<-MESSAGE.strip_heredoc
611
+ Expected errors to include "must be greater than 18" when attr is set to "18",
612
+ got no errors
613
+ MESSAGE
706
614
  expect(&assertion).to fail_with_message(message)
707
615
  end
708
616
 
@@ -717,12 +625,10 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
717
625
  odd.
718
626
  is_less_than_or_equal_to(99)
719
627
  end
720
- message = format_message_according_to_rails_version(
721
- <<-MESSAGE.strip_heredoc
722
- Expected errors to include "must be less than or equal to 99" when attr is set to 101,
723
- got no errors
724
- MESSAGE
725
- )
628
+ message = <<-MESSAGE.strip_heredoc
629
+ Expected errors to include "must be less than or equal to 99" when attr is set to "101",
630
+ got no errors
631
+ MESSAGE
726
632
  expect(&assertion).to fail_with_message(message)
727
633
  end
728
634
 
@@ -737,13 +643,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
737
643
  odd.
738
644
  is_less_than_or_equal_to(99)
739
645
  end
740
- message = format_message_according_to_rails_version(
741
- <<-MESSAGE.strip_heredoc
742
- Expected errors to include "must be less than or equal to 99" when attr is set to 101,
743
- got errors:
744
- * "must be less than or equal to 97" (attribute: attr, value: "101")
745
- MESSAGE
746
- )
646
+ message = <<-MESSAGE.strip_heredoc
647
+ Expected errors to include "must be less than or equal to 99" when attr is set to "101",
648
+ got errors:
649
+ * "must be less than or equal to 97" (attribute: attr, value: "101")
650
+ MESSAGE
747
651
  expect(&assertion).to fail_with_message(message)
748
652
  end
749
653
 
@@ -760,13 +664,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
760
664
  is_greater_than(18).
761
665
  is_less_than(99)
762
666
  end
763
- message = format_message_according_to_rails_version(
764
- <<-MESSAGE.strip_heredoc
765
- Expected errors to include "must be greater than 18" when attr is set to 18,
766
- got errors:
767
- * "must be greater than 19" (attribute: attr, value: "19")
768
- MESSAGE
769
- )
667
+ message = <<-MESSAGE.strip_heredoc
668
+ Expected errors to include "must be greater than 18" when attr is set to "18",
669
+ got errors:
670
+ * "must be greater than 19" (attribute: attr, value: "19")
671
+ MESSAGE
770
672
  expect(&assertion).to fail_with_message(message)
771
673
  end
772
674
 
@@ -783,13 +685,11 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
783
685
  is_greater_than(18).
784
686
  is_less_than(99)
785
687
  end
786
- message = format_message_according_to_rails_version(
787
- <<-MESSAGE.strip_heredoc
788
- Expected errors to include "must be less than 99" when attr is set to 100,
789
- got errors:
790
- * "must be less than 100" (attribute: attr, value: "100")
791
- MESSAGE
792
- )
688
+ message = <<-MESSAGE.strip_heredoc
689
+ Expected errors to include "must be less than 99" when attr is set to "100",
690
+ got errors:
691
+ * "must be less than 100" (attribute: attr, value: "100")
692
+ MESSAGE
793
693
  expect(&assertion).to fail_with_message(message)
794
694
  end
795
695
  end
@@ -970,23 +870,4 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher, type: :m
970
870
  def attribute_name
971
871
  :attr
972
872
  end
973
-
974
- def define_model_with_integer_column_of_limit(limit, validation_options = {})
975
- column_options = { type: :integer, options: { limit: limit } }
976
- define_model :example, attribute_name => column_options do |model|
977
- model.validates_numericality_of(attribute_name, validation_options)
978
- end
979
- end
980
-
981
- def build_record_with_integer_column_of_limit(limit, validation_options = {})
982
- define_model_with_integer_column_of_limit(limit, validation_options).new
983
- end
984
-
985
- def format_message_according_to_rails_version(message)
986
- if rails_gte_4_2?
987
- message
988
- else
989
- message.gsub(/"((?:\d+)(?:\.\d+)?)"/, '\1')
990
- end
991
- end
992
873
  end
@@ -163,6 +163,20 @@ describe Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher, type: :model
163
163
  end
164
164
  end
165
165
 
166
+ context 'when the attribute typecasts nil to an empty array' do
167
+ it 'accepts' do
168
+ model = define_active_model_class :example do
169
+ attr_reader :foo
170
+
171
+ def foo=(value)
172
+ @foo = Array.wrap(value)
173
+ end
174
+ end
175
+
176
+ expect(model.new).to validate_presence_of(:foo)
177
+ end
178
+ end
179
+
166
180
  def matcher
167
181
  validate_presence_of(:attr)
168
182
  end