shoulda-matchers 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +1 -1
  3. data/.hound/ruby.yml +1042 -0
  4. data/{.hound_config/ruby.yml → .rubocop.yml} +7 -6
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +26 -32
  7. data/NEWS.md +18 -0
  8. data/README.md +32 -6
  9. data/docs/errors/NonCaseSwappableValueError.md +2 -2
  10. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +6 -6
  11. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +7 -8
  13. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  14. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
  15. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +2 -2
  16. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  17. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -3
  18. data/lib/shoulda/matchers/action_controller/route_matcher.rb +2 -2
  19. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +4 -4
  20. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
  21. data/lib/shoulda/matchers/active_model.rb +1 -1
  22. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +3 -3
  23. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +10 -10
  24. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +1 -1
  25. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +3 -3
  26. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +3 -3
  27. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +3 -3
  28. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +4 -4
  29. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +8 -8
  30. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +8 -8
  31. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +12 -12
  32. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +4 -4
  33. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +4 -4
  34. data/lib/shoulda/matchers/active_record/association_matcher.rb +61 -43
  35. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -3
  36. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +3 -3
  37. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +3 -3
  38. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +1 -1
  39. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -3
  40. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +11 -11
  41. data/lib/shoulda/matchers/version.rb +1 -1
  42. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +9 -0
  43. metadata +5 -5
@@ -12,7 +12,7 @@ module Shoulda
12
12
  # end
13
13
  #
14
14
  # # RSpec
15
- # describe Robot do
15
+ # RSpec.describe Robot, type: :model do
16
16
  # it { should validate_presence_of(:arms) }
17
17
  # end
18
18
  #
@@ -36,7 +36,7 @@ module Shoulda
36
36
  # validates_presence_of :password
37
37
  # end
38
38
  #
39
- # describe User do
39
+ # RSpec.describe User, type: :model do
40
40
  # subject { User.new(password: '123456') }
41
41
  #
42
42
  # it { should validate_presence_of(:password) }
@@ -69,7 +69,7 @@ module Shoulda
69
69
  # end
70
70
  #
71
71
  # # RSpec
72
- # describe Robot do
72
+ # RSpec.describe Robot, type: :model do
73
73
  # it { should validate_presence_of(:arms).on(:create) }
74
74
  # end
75
75
  #
@@ -90,7 +90,7 @@ module Shoulda
90
90
  # end
91
91
  #
92
92
  # # RSpec
93
- # describe Robot do
93
+ # RSpec.describe Robot, type: :model do
94
94
  # it do
95
95
  # should validate_presence_of(:legs).
96
96
  # with_message('Robot has no legs')
@@ -9,7 +9,7 @@ module Shoulda
9
9
  # end
10
10
  #
11
11
  # # RSpec
12
- # describe Car do
12
+ # RSpec.describe Car, type: :model do
13
13
  # it { should accept_nested_attributes_for(:doors) }
14
14
  # end
15
15
  #
@@ -30,7 +30,7 @@ module Shoulda
30
30
  # end
31
31
  #
32
32
  # # RSpec
33
- # describe Car do
33
+ # RSpec.describe Car, type: :model do
34
34
  # it do
35
35
  # should accept_nested_attributes_for(:mirrors).
36
36
  # allow_destroy(true)
@@ -52,7 +52,7 @@ module Shoulda
52
52
  # end
53
53
  #
54
54
  # # RSpec
55
- # describe Car do
55
+ # RSpec.describe Car, type: :model do
56
56
  # it do
57
57
  # should accept_nested_attributes_for(:windows).
58
58
  # limit(3)
@@ -75,7 +75,7 @@ module Shoulda
75
75
  # end
76
76
  #
77
77
  # # RSpec
78
- # describe Car do
78
+ # RSpec.describe Car, type: :model do
79
79
  # it do
80
80
  # should accept_nested_attributes_for(:engine).
81
81
  # update_only(true)
@@ -11,7 +11,7 @@ module Shoulda
11
11
  # end
12
12
  #
13
13
  # # RSpec
14
- # describe Person do
14
+ # RSpec.describe Person, type: :model do
15
15
  # it { should belong_to(:organization) }
16
16
  # end
17
17
  #
@@ -28,7 +28,7 @@ module Shoulda
28
28
  # end
29
29
  #
30
30
  # # RSpec
31
- # describe Comment do
31
+ # RSpec.describe Comment, type: :model do
32
32
  # it { should belong_to(:commentable) }
33
33
  # end
34
34
  #
@@ -49,7 +49,7 @@ module Shoulda
49
49
  # end
50
50
  #
51
51
  # # RSpec
52
- # describe Person do
52
+ # RSpec.describe Person, type: :model do
53
53
  # it do
54
54
  # should belong_to(:family).
55
55
  # conditions(everyone_is_perfect: false)
@@ -72,7 +72,7 @@ module Shoulda
72
72
  # end
73
73
  #
74
74
  # # RSpec
75
- # describe Person do
75
+ # RSpec.describe Person, type: :model do
76
76
  # it { should belong_to(:previous_company).order('hired_on desc') }
77
77
  # end
78
78
  #
@@ -91,7 +91,7 @@ module Shoulda
91
91
  # end
92
92
  #
93
93
  # # RSpec
94
- # describe Person do
94
+ # RSpec.describe Person, type: :model do
95
95
  # it { should belong_to(:ancient_city).class_name('City') }
96
96
  # end
97
97
  #
@@ -109,7 +109,7 @@ module Shoulda
109
109
  # end
110
110
  #
111
111
  # # RSpec
112
- # describe Person do
112
+ # RSpec.describe Person, type: :model do
113
113
  # it do
114
114
  # should belong_to(:great_country).
115
115
  # with_primary_key('country_id')
@@ -131,7 +131,7 @@ module Shoulda
131
131
  # end
132
132
  #
133
133
  # # RSpec
134
- # describe Person do
134
+ # RSpec.describe Person, type: :model do
135
135
  # it do
136
136
  # should belong_to(:great_country).
137
137
  # with_foreign_key('country_id')
@@ -153,7 +153,7 @@ module Shoulda
153
153
  # end
154
154
  #
155
155
  # # RSpec
156
- # describe Person do
156
+ # RSpec.describe Person, type: :model do
157
157
  # it { should belong_to(:world).dependent(:destroy) }
158
158
  # end
159
159
  #
@@ -165,7 +165,7 @@ module Shoulda
165
165
  # To assert that *any* `:dependent` option was specified, use `true`:
166
166
  #
167
167
  # # RSpec
168
- # describe Person do
168
+ # RSpec.describe Person, type: :model do
169
169
  # it { should belong_to(:world).dependent(true) }
170
170
  # end
171
171
  #
@@ -176,7 +176,7 @@ module Shoulda
176
176
  # end
177
177
  #
178
178
  # # RSpec
179
- # describe Person do
179
+ # RSpec.describe Person, type: :model do
180
180
  # it { should belong_to(:company).dependent(false) }
181
181
  # end
182
182
  #
@@ -190,7 +190,7 @@ module Shoulda
190
190
  # end
191
191
  #
192
192
  # # RSpec
193
- # describe Person do
193
+ # RSpec.describe Person, type: :model do
194
194
  # it { should belong_to(:organization).counter_cache(true) }
195
195
  # end
196
196
  #
@@ -208,7 +208,7 @@ module Shoulda
208
208
  # end
209
209
  #
210
210
  # # RSpec
211
- # describe Person do
211
+ # RSpec.describe Person, type: :model do
212
212
  # it { should belong_to(:organization).touch(true) }
213
213
  # end
214
214
  #
@@ -226,7 +226,7 @@ module Shoulda
226
226
  # end
227
227
  #
228
228
  # # RSpec
229
- # describe Account do
229
+ # RSpec.describe Account, type: :model do
230
230
  # it { should belong_to(:bank).autosave(true) }
231
231
  # end
232
232
  #
@@ -267,7 +267,7 @@ module Shoulda
267
267
  # end
268
268
  #
269
269
  # # RSpec
270
- # describe Person do
270
+ # RSpec.describe Person, type: :model do
271
271
  # it { should have_many(:friends) }
272
272
  # end
273
273
  #
@@ -284,7 +284,7 @@ module Shoulda
284
284
  # end
285
285
  #
286
286
  # # RSpec
287
- # describe Person do
287
+ # RSpec.describe Person, type: :model do
288
288
  # it { should have_many(:pictures) }
289
289
  # end
290
290
  #
@@ -305,7 +305,7 @@ module Shoulda
305
305
  # end
306
306
  #
307
307
  # # RSpec
308
- # describe Person do
308
+ # RSpec.describe Person, type: :model do
309
309
  # it { should have_many(:coins).conditions(quality: 'mint') }
310
310
  # end
311
311
  #
@@ -324,7 +324,7 @@ module Shoulda
324
324
  # end
325
325
  #
326
326
  # # RSpec
327
- # describe Person do
327
+ # RSpec.describe Person, type: :model do
328
328
  # it { should have_many(:shirts).order('color') }
329
329
  # end
330
330
  #
@@ -343,7 +343,7 @@ module Shoulda
343
343
  # end
344
344
  #
345
345
  # # RSpec
346
- # describe Person do
346
+ # RSpec.describe Person, type: :model do
347
347
  # it { should have_many(:hopes).class_name('Dream') }
348
348
  # end
349
349
  #
@@ -361,7 +361,7 @@ module Shoulda
361
361
  # end
362
362
  #
363
363
  # # RSpec
364
- # describe Person do
364
+ # RSpec.describe Person, type: :model do
365
365
  # it { should have_many(:worries).with_primary_key('worrier_id') }
366
366
  # end
367
367
  #
@@ -379,7 +379,7 @@ module Shoulda
379
379
  # end
380
380
  #
381
381
  # # RSpec
382
- # describe Person do
382
+ # RSpec.describe Person, type: :model do
383
383
  # it { should have_many(:worries).with_foreign_key('worrier_id') }
384
384
  # end
385
385
  #
@@ -397,7 +397,7 @@ module Shoulda
397
397
  # end
398
398
  #
399
399
  # # RSpec
400
- # describe Person do
400
+ # RSpec.describe Person, type: :model do
401
401
  # it { should have_many(:secret_documents).dependent(:destroy) }
402
402
  # end
403
403
  #
@@ -416,7 +416,7 @@ module Shoulda
416
416
  # end
417
417
  #
418
418
  # # RSpec
419
- # describe Person do
419
+ # RSpec.describe Person, type: :model do
420
420
  # it { should have_many(:acquaintances).through(:friends) }
421
421
  # end
422
422
  #
@@ -435,7 +435,7 @@ module Shoulda
435
435
  # end
436
436
  #
437
437
  # # RSpec
438
- # describe Person do
438
+ # RSpec.describe Person, type: :model do
439
439
  # it do
440
440
  # should have_many(:job_offers).
441
441
  # through(:friends).
@@ -459,7 +459,7 @@ module Shoulda
459
459
  # end
460
460
  #
461
461
  # # RSpec
462
- # describe Person do
462
+ # RSpec.describe Person, type: :model do
463
463
  # it { should have_many(:ideas).validate(false) }
464
464
  # end
465
465
  #
@@ -477,7 +477,7 @@ module Shoulda
477
477
  # end
478
478
  #
479
479
  # # RSpec
480
- # describe Player do
480
+ # RSpec.describe Player, type: :model do
481
481
  # it { should have_many(:games).autosave(true) }
482
482
  # end
483
483
  #
@@ -486,6 +486,24 @@ module Shoulda
486
486
  # should have_many(:games).autosave(true)
487
487
  # end
488
488
  #
489
+ # ##### inverse_of
490
+ #
491
+ # Use `inverse_of` to assert that the `:inverse_of` option was specified.
492
+ #
493
+ # class Organization < ActiveRecord::Base
494
+ # has_many :employees, inverse_of: :company
495
+ # end
496
+ #
497
+ # # RSpec
498
+ # describe Organization
499
+ # it { should have_many(:employees).inverse_of(:company) }
500
+ # end
501
+ #
502
+ # # Minitest (Shoulda)
503
+ # class OrganizationTest < ActiveSupport::TestCase
504
+ # should have_many(:employees).inverse_of(:company)
505
+ # end
506
+ #
489
507
  # @return [AssociationMatcher]
490
508
  #
491
509
  def have_many(name)
@@ -500,7 +518,7 @@ module Shoulda
500
518
  # end
501
519
  #
502
520
  # # RSpec
503
- # describe Person do
521
+ # RSpec.describe Person, type: :model do
504
522
  # it { should have_one(:partner) }
505
523
  # end
506
524
  #
@@ -521,7 +539,7 @@ module Shoulda
521
539
  # end
522
540
  #
523
541
  # # RSpec
524
- # describe Person do
542
+ # RSpec.describe Person, type: :model do
525
543
  # it { should have_one(:pet).conditions('weight < 80') }
526
544
  # end
527
545
  #
@@ -540,7 +558,7 @@ module Shoulda
540
558
  # end
541
559
  #
542
560
  # # RSpec
543
- # describe Person do
561
+ # RSpec.describe Person, type: :model do
544
562
  # it { should have_one(:focus).order('priority desc') }
545
563
  # end
546
564
  #
@@ -559,7 +577,7 @@ module Shoulda
559
577
  # end
560
578
  #
561
579
  # # RSpec
562
- # describe Person do
580
+ # RSpec.describe Person, type: :model do
563
581
  # it { should have_one(:chance).class_name('Opportunity') }
564
582
  # end
565
583
  #
@@ -577,7 +595,7 @@ module Shoulda
577
595
  # end
578
596
  #
579
597
  # # RSpec
580
- # describe Person do
598
+ # RSpec.describe Person, type: :model do
581
599
  # it { should have_one(:contract).dependent(:nullify) }
582
600
  # end
583
601
  #
@@ -595,7 +613,7 @@ module Shoulda
595
613
  # end
596
614
  #
597
615
  # # RSpec
598
- # describe Person do
616
+ # RSpec.describe Person, type: :model do
599
617
  # it { should have_one(:job).with_primary_key('worker_id') }
600
618
  # end
601
619
  #
@@ -613,7 +631,7 @@ module Shoulda
613
631
  # end
614
632
  #
615
633
  # # RSpec
616
- # describe Person do
634
+ # RSpec.describe Person, type: :model do
617
635
  # it { should have_one(:job).with_foreign_key('worker_id') }
618
636
  # end
619
637
  #
@@ -632,7 +650,7 @@ module Shoulda
632
650
  # end
633
651
  #
634
652
  # # RSpec
635
- # describe Person do
653
+ # RSpec.describe Person, type: :model do
636
654
  # it { should have_one(:life).through(:partner) }
637
655
  # end
638
656
  #
@@ -651,7 +669,7 @@ module Shoulda
651
669
  # end
652
670
  #
653
671
  # # RSpec
654
- # describe Person do
672
+ # RSpec.describe Person, type: :model do
655
673
  # it { should have_one(:car).through(:partner).source(:vehicle) }
656
674
  # end
657
675
  #
@@ -669,7 +687,7 @@ module Shoulda
669
687
  # end
670
688
  #
671
689
  # # RSpec
672
- # describe Person do
690
+ # RSpec.describe Person, type: :model do
673
691
  # it { should have_one(:parking_card).validate(false) }
674
692
  # end
675
693
  #
@@ -687,7 +705,7 @@ module Shoulda
687
705
  # end
688
706
  #
689
707
  # # RSpec
690
- # describe Account do
708
+ # RSpec.describe Account, type: :model do
691
709
  # it { should have_one(:bank).autosave(true) }
692
710
  # end
693
711
  #
@@ -711,7 +729,7 @@ module Shoulda
711
729
  # end
712
730
  #
713
731
  # # RSpec
714
- # describe Person do
732
+ # RSpec.describe Person, type: :model do
715
733
  # it { should have_and_belong_to_many(:awards) }
716
734
  # end
717
735
  #
@@ -732,7 +750,7 @@ module Shoulda
732
750
  # end
733
751
  #
734
752
  # # RSpec
735
- # describe Person do
753
+ # RSpec.describe Person, type: :model do
736
754
  # it do
737
755
  # should have_and_belong_to_many(:issues).
738
756
  # conditions(difficulty: 'hard')
@@ -755,7 +773,7 @@ module Shoulda
755
773
  # end
756
774
  #
757
775
  # # RSpec
758
- # describe Person do
776
+ # RSpec.describe Person, type: :model do
759
777
  # it do
760
778
  # should have_and_belong_to_many(:projects).
761
779
  # order('time_spent')
@@ -778,7 +796,7 @@ module Shoulda
778
796
  # end
779
797
  #
780
798
  # # RSpec
781
- # describe Person do
799
+ # RSpec.describe Person, type: :model do
782
800
  # it do
783
801
  # should have_and_belong_to_many(:places_visited).
784
802
  # class_name('City')
@@ -801,7 +819,7 @@ module Shoulda
801
819
  # end
802
820
  #
803
821
  # # RSpec
804
- # describe Person do
822
+ # RSpec.describe Person, type: :model do
805
823
  # it do
806
824
  # should have_and_belong_to_many(:issues).
807
825
  # join_table('people_tickets')
@@ -823,7 +841,7 @@ module Shoulda
823
841
  # end
824
842
  #
825
843
  # # RSpec
826
- # describe Person do
844
+ # RSpec.describe Person, type: :model do
827
845
  # it do
828
846
  # should have_and_belong_to_many(:interviews).
829
847
  # validate(false)
@@ -845,7 +863,7 @@ module Shoulda
845
863
  # end
846
864
  #
847
865
  # # RSpec
848
- # describe Publisher do
866
+ # RSpec.describe Publisher, type: :model do
849
867
  # it { should have_and_belong_to_many(:advertisers).autosave(true) }
850
868
  # end
851
869
  #