shoulda-matchers 3.0.1 → 3.1.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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -3
  4. data/CONTRIBUTING.md +60 -28
  5. data/Gemfile +1 -0
  6. data/Gemfile.lock +15 -12
  7. data/NEWS.md +111 -0
  8. data/README.md +94 -6
  9. data/Rakefile +10 -8
  10. data/custom_plan.rb +88 -0
  11. data/gemfiles/4.0.0.gemfile +1 -0
  12. data/gemfiles/4.0.0.gemfile.lock +21 -18
  13. data/gemfiles/4.0.1.gemfile +1 -0
  14. data/gemfiles/4.0.1.gemfile.lock +21 -18
  15. data/gemfiles/4.1.gemfile +1 -0
  16. data/gemfiles/4.1.gemfile.lock +21 -18
  17. data/gemfiles/4.2.gemfile +1 -0
  18. data/gemfiles/4.2.gemfile.lock +24 -21
  19. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +6 -11
  20. data/lib/shoulda/matchers/active_model.rb +10 -1
  21. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +258 -180
  22. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +45 -0
  23. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb +23 -0
  24. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +236 -0
  25. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +62 -0
  26. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +40 -0
  27. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +48 -0
  28. data/lib/shoulda/matchers/active_model/allow_value_matcher/successful_check.rb +14 -0
  29. data/lib/shoulda/matchers/active_model/allow_value_matcher/successful_setting.rb +14 -0
  30. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +34 -14
  31. data/lib/shoulda/matchers/active_model/helpers.rb +9 -17
  32. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +13 -6
  33. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +13 -2
  34. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +19 -35
  35. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +13 -2
  36. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +12 -2
  37. data/lib/shoulda/matchers/active_model/qualifiers.rb +12 -0
  38. data/lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb +101 -0
  39. data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +21 -0
  40. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +30 -32
  41. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +5 -8
  42. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -22
  43. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +27 -16
  44. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +58 -15
  45. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +22 -12
  46. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +165 -87
  47. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +7 -9
  48. data/lib/shoulda/matchers/active_model/validation_matcher.rb +111 -49
  49. data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +60 -0
  50. data/lib/shoulda/matchers/active_model/validator.rb +71 -52
  51. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +19 -5
  52. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +450 -124
  53. data/lib/shoulda/matchers/util.rb +43 -0
  54. data/lib/shoulda/matchers/util/word_wrap.rb +59 -31
  55. data/lib/shoulda/matchers/version.rb +1 -1
  56. data/script/update_gem_in_all_appraisals +1 -1
  57. data/script/update_gems_in_all_appraisals +1 -1
  58. data/spec/acceptance/multiple_libraries_integration_spec.rb +5 -2
  59. data/spec/acceptance/rails_integration_spec.rb +6 -2
  60. data/spec/spec_helper.rb +1 -3
  61. data/spec/support/acceptance/helpers/step_helpers.rb +4 -1
  62. data/spec/support/tests/current_bundle.rb +21 -7
  63. data/spec/support/unit/active_record/create_table.rb +54 -0
  64. data/spec/support/unit/attribute.rb +47 -0
  65. data/spec/support/unit/capture.rb +6 -0
  66. data/spec/support/unit/change_value.rb +111 -0
  67. data/spec/support/unit/create_model_arguments/basic.rb +135 -0
  68. data/spec/support/unit/create_model_arguments/has_many.rb +15 -0
  69. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +74 -0
  70. data/spec/support/unit/helpers/active_record_versions.rb +1 -1
  71. data/spec/support/unit/helpers/class_builder.rb +61 -47
  72. data/spec/support/unit/helpers/database_helpers.rb +5 -3
  73. data/spec/support/unit/helpers/model_builder.rb +77 -97
  74. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +44 -0
  75. data/spec/support/unit/load_environment.rb +12 -0
  76. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +2 -2
  77. data/spec/support/unit/matchers/fail_with_message_matcher.rb +12 -1
  78. data/spec/support/unit/model_creation_strategies/active_model.rb +111 -0
  79. data/spec/support/unit/model_creation_strategies/active_record.rb +77 -0
  80. data/spec/support/unit/model_creators.rb +19 -0
  81. data/spec/support/unit/model_creators/active_model.rb +39 -0
  82. data/spec/support/unit/model_creators/active_record.rb +43 -0
  83. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +95 -0
  84. data/spec/support/unit/model_creators/active_record/has_many.rb +67 -0
  85. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +42 -0
  86. data/spec/support/unit/model_creators/basic.rb +97 -0
  87. data/spec/support/unit/rails_application.rb +1 -1
  88. data/spec/support/unit/record_validating_confirmation_builder.rb +3 -7
  89. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +79 -0
  90. data/spec/support/unit/validation_matcher_scenario.rb +62 -0
  91. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +4 -0
  92. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +575 -140
  93. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +115 -15
  94. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +42 -4
  95. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +92 -6
  96. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +122 -10
  97. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +306 -58
  98. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +122 -3
  99. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +805 -131
  100. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +196 -29
  101. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +82 -40
  102. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +600 -101
  103. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +88 -33
  104. data/spec/unit_spec_helper.rb +10 -22
  105. data/zeus.json +11 -0
  106. metadata +64 -23
  107. data/lib/shoulda/matchers/active_model/strict_validator.rb +0 -51
  108. data/spec/support/unit/shared_examples/numerical_type_submatcher.rb +0 -15
  109. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +0 -288
  110. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +0 -100
  111. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +0 -100
  112. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +0 -100
@@ -1,100 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OddNumberMatcher do
4
- subject { described_class.new(numericality_matcher, :attr) }
5
-
6
- it_behaves_like 'a numerical submatcher'
7
- it_behaves_like 'a numerical type submatcher'
8
-
9
- it 'allows odd number' do
10
- expect(subject.allowed_type).to eq 'odd numbers'
11
- end
12
-
13
- describe '#diff_to_compare' do
14
- it { expect(subject.diff_to_compare).to eq 2 }
15
- end
16
-
17
- context 'when the model has an odd validation' do
18
- it 'matches' do
19
- match = subject
20
- expect(validating_odd_number).to match
21
- end
22
- end
23
-
24
- context 'when the model does not have an odd validation' do
25
- it 'does not match' do
26
- match = subject
27
- expect(not_validating_odd_number).not_to match
28
- end
29
-
30
- it 'fails with the ActiveRecord :odd message' do
31
- match = subject
32
- expect {
33
- expect(not_validating_odd_number).to match
34
- }.to fail_with_message_including('Expected errors to include "must be odd"')
35
- end
36
- end
37
-
38
- context 'with custom validation message' do
39
- it 'only accepts odd number values for that attribute with that message' do
40
- expect(validating_odd_number(message: 'custom')).to subject.with_message(/custom/)
41
- end
42
-
43
- it 'fails odd number values for that attribute with another message' do
44
- expect(validating_odd_number(message: 'custom')).not_to subject.with_message(/wrong/)
45
- end
46
- end
47
-
48
- context 'asserting strict validation when validating strictly' do
49
- it 'accepts' do
50
- expect(validating_odd_number(strict: true)).to subject.strict
51
- end
52
- end
53
-
54
- context 'asserting non-strict validation when validating strictly' do
55
- it 'rejects' do
56
- pending 'This needs to be fixed'
57
- expect(validating_odd_number(strict: true)).not_to subject
58
- end
59
- end
60
-
61
- context 'asserting strict validation when not validating strictly' do
62
- it 'rejects' do
63
- expect(validating_odd_number).not_to subject.strict
64
- end
65
- end
66
-
67
- context 'qualified with on and validating with on' do
68
- it 'accepts' do
69
- expect(validating_odd_number(on: :customizable)).
70
- to subject.on(:customizable)
71
- end
72
- end
73
-
74
- context 'qualified with on but not validating with on' do
75
- it 'accepts since the validation never considers a context' do
76
- expect(validating_odd_number).to subject.on(:customizable)
77
- end
78
- end
79
-
80
- context 'not qualified with on but validating with on' do
81
- it 'rejects since the validation never runs' do
82
- expect(validating_odd_number(on: :customizable)).
83
- not_to subject
84
- end
85
- end
86
-
87
- def numericality_matcher
88
- double(:numericality_matcher, given_numeric_column?: nil)
89
- end
90
-
91
- def validating_odd_number(options = {})
92
- define_model :example, attr: :string do
93
- validates_numericality_of :attr, { odd: true }.merge(options)
94
- end.new
95
- end
96
-
97
- def not_validating_odd_number
98
- define_model(:example, attr: :string).new
99
- end
100
- end
@@ -1,100 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::OnlyIntegerMatcher do
4
- subject { described_class.new(numericality_matcher, :attr) }
5
-
6
- it_behaves_like 'a numerical submatcher'
7
- it_behaves_like 'a numerical type submatcher'
8
-
9
- it 'allows integer types' do
10
- expect(subject.allowed_type).to eq 'integers'
11
- end
12
-
13
- describe '#diff_to_compare' do
14
- it { expect(subject.diff_to_compare).to eq 1 }
15
- end
16
-
17
- context 'given an attribute that only allows integer values' do
18
- it 'matches' do
19
- match = subject
20
- expect(validating_only_integer).to match
21
- end
22
- end
23
-
24
- context 'given an attribute that only allows integer values with a custom validation message' do
25
- it 'only accepts integer values for that attribute with that message' do
26
- expect(validating_only_integer(message: 'custom')).to subject.with_message(/custom/)
27
- end
28
-
29
- it 'rejects integer values for that attribute with another message' do
30
- expect(validating_only_integer(message: 'custom')).not_to subject.with_message(/wrong/)
31
- end
32
- end
33
-
34
- context 'when the model does not have an only_integer validation' do
35
- it 'does not match' do
36
- match = subject
37
- expect(not_validating_only_integer).not_to match
38
- end
39
-
40
- it 'fails with the ActiveRecord :not_an_integer message' do
41
- match = subject
42
- expect {
43
- expect(not_validating_only_integer).to match
44
- }.to fail_with_message_including('Expected errors to include "must be an integer"')
45
- end
46
- end
47
-
48
- context 'asserting strict validation when validating strictly' do
49
- it 'accepts' do
50
- expect(validating_only_integer(strict: true)).to subject.strict
51
- end
52
- end
53
-
54
- context 'asserting non-strict validation when validating strictly' do
55
- it 'rejects' do
56
- pending 'This needs to be fixed'
57
- expect(validating_only_integer(strict: true)).not_to subject
58
- end
59
- end
60
-
61
- context 'asserting strict validation when not validating strictly' do
62
- it 'rejects' do
63
- expect(validating_only_integer).not_to subject.strict
64
- end
65
- end
66
-
67
- context 'qualified with on and validating with on' do
68
- it 'accepts' do
69
- expect(validating_only_integer(on: :customizable)).
70
- to subject.on(:customizable)
71
- end
72
- end
73
-
74
- context 'qualified with on but not validating with on' do
75
- it 'accepts since the validation never considers a context' do
76
- expect(validating_only_integer).to subject.on(:customizable)
77
- end
78
- end
79
-
80
- context 'not qualified with on but validating with on' do
81
- it 'rejects since the validation never runs' do
82
- expect(validating_only_integer(on: :customizable)).
83
- not_to subject
84
- end
85
- end
86
-
87
- def numericality_matcher
88
- double(:numericality_matcher, given_numeric_column?: nil)
89
- end
90
-
91
- def validating_only_integer(options = {})
92
- define_model :example, attr: :string do
93
- validates_numericality_of :attr, { only_integer: true }.merge(options)
94
- end.new
95
- end
96
-
97
- def not_validating_only_integer
98
- define_model(:example, attr: :string).new
99
- end
100
- end