shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
@@ -1,109 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveModel::ValidateAcceptanceOfMatcher, type: :model do
4
- context 'a model with an acceptance validation' do
5
- it 'accepts when the attributes match' do
6
- expect(record_validating_acceptance).to matcher
7
- end
8
-
9
- it 'does not overwrite the default message with nil' do
10
- expect(record_validating_acceptance).to matcher.with_message(nil)
11
- end
12
-
13
- it_supports(
14
- 'ignoring_interference_by_writer',
15
- tests: {
16
- accept_if_qualified_but_changing_value_does_not_interfere: {
17
- changing_values_with: :never_falsy,
18
- },
19
- reject_if_qualified_but_changing_value_interferes: {
20
- model_name: 'Example',
21
- attribute_name: :attr,
22
- changing_values_with: :always_nil,
23
- expected_message: <<-MESSAGE.strip
24
- Expected Example to validate that :attr has been set to "1", but this
25
- could not be proved.
26
- After setting :attr to ‹false› -- which was read back as ‹nil› -- the
27
- matcher expected the Example to be invalid, but it was valid instead.
28
-
29
- As indicated in the message above, :attr seems to be changing certain
30
- values as they are set, and this could have something to do with why
31
- this test is failing. If you've overridden the writer method for this
32
- attribute, then you may need to change it to make this test pass, or
33
- do something else entirely.
34
- MESSAGE
35
- },
36
- },
37
- model_creator: :active_model
38
- )
39
-
40
- it 'fails when used in the negative' do
41
- assertion = lambda do
42
- expect(record_validating_acceptance).not_to matcher
43
- end
44
-
45
- message = <<-MESSAGE
46
- Expected Example not to validate that :attr has been set to "1", but
47
- this could not be proved.
48
- After setting :attr to ‹false›, the matcher expected the Example to be
49
- valid, but it was invalid instead, producing these validation errors:
50
-
51
- * attr: ["must be accepted"]
52
- MESSAGE
53
-
54
- expect(&assertion).to fail_with_message(message)
55
- end
56
- end
57
-
58
- context 'a model without an acceptance validation' do
59
- it 'rejects' do
60
- expect(record_validating_nothing).not_to matcher
61
- end
62
- end
63
-
64
- context 'an attribute which must be accepted with a custom message' do
65
- it 'accepts when the message matches' do
66
- expect(record_validating_acceptance(message: 'custom')).
67
- to matcher.with_message(/custom/)
68
- end
69
-
70
- it 'rejects when the message does not match' do
71
- expect(record_validating_acceptance(message: 'custom')).
72
- not_to matcher.with_message(/wrong/)
73
- end
74
- end
75
-
76
- def matcher
77
- validate_acceptance_of(:attr)
78
- end
79
-
80
- def model_validating_nothing(options = {}, &block)
81
- attribute_name = options.fetch(:attribute_name, :attr)
82
- define_active_model_class(:example, accessors: [attribute_name], &block)
83
- end
84
-
85
- def record_validating_nothing
86
- model_validating_nothing.new
87
- end
88
-
89
- def model_validating_acceptance(options = {})
90
- attribute_name = options.fetch(:attribute_name, :attr)
91
-
92
- model_validating_nothing(attribute_name: attribute_name) do
93
- validates_acceptance_of attribute_name, options
94
- end
95
- end
96
-
97
- alias_method :define_model_validating_acceptance, :model_validating_acceptance
98
-
99
- def record_validating_acceptance(options = {})
100
- model_validating_acceptance(options).new
101
- end
102
-
103
- alias_method :build_record_validating_acceptance,
104
- :record_validating_acceptance
105
-
106
- def validation_matcher_scenario_args
107
- { matcher_name: :validate_acceptance_of }
108
- end
109
- end
@@ -1,172 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher, type: :model do
4
- include UnitTests::ConfirmationMatcherHelpers
5
-
6
- context '#description' do
7
- it 'states that the confirmation must match its base attribute' do
8
- builder = builder_for_record_validating_confirmation
9
- message = "validate that :#{builder.confirmation_attribute} matches :#{builder.attribute_to_confirm}"
10
- matcher = described_class.new(builder.attribute_to_confirm)
11
- expect(matcher.description).to eq(message)
12
- end
13
- end
14
-
15
- context 'when the model has a confirmation validation' do
16
- it 'passes' do
17
- builder = builder_for_record_validating_confirmation
18
- expect(builder.record).
19
- to validate_confirmation_of(builder.attribute_to_confirm)
20
- end
21
-
22
- context 'when a nil message is specified' do
23
- it 'ignores it' do
24
- builder = builder_for_record_validating_confirmation
25
- expect(builder.record).
26
- to validate_confirmation_of(builder.attribute_to_confirm).
27
- with_message(nil)
28
- end
29
- end
30
-
31
- it_supports(
32
- 'ignoring_interference_by_writer',
33
- tests: {
34
- reject_if_qualified_but_changing_value_interferes: {
35
- model_name: 'Example',
36
- attribute_name: :password,
37
- changing_values_with: :next_value,
38
- expected_message: <<-MESSAGE.strip
39
- Expected Example to validate that :password_confirmation matches
40
- :password, but this could not be proved.
41
- After setting :password_confirmation to ‹"same value"›, then setting
42
- :password to ‹"same value"› -- which was read back as ‹"same valuf"›
43
- -- the matcher expected the Example to be valid, but it was invalid
44
- instead, producing these validation errors:
45
-
46
- * password_confirmation: ["doesn't match Password"]
47
-
48
- As indicated in the message above, :password seems to be changing
49
- certain values as they are set, and this could have something to do
50
- with why this test is failing. If you've overridden the writer method
51
- for this attribute, then you may need to change it to make this test
52
- pass, or do something else entirely.
53
- MESSAGE
54
- },
55
- },
56
- model_creator: :active_model
57
- )
58
-
59
- it 'fails when used in the negative' do
60
- builder = builder_for_record_validating_confirmation(
61
- model_name: 'Example',
62
- attribute: :password,
63
- confirmation_attribute: :password_confirmation
64
- )
65
-
66
- assertion = lambda do
67
- expect(builder.record).
68
- not_to validate_confirmation_of(builder.attribute_to_confirm)
69
- end
70
-
71
- message = <<-MESSAGE
72
- Expected Example not to validate that :password_confirmation matches
73
- :password, but this could not be proved.
74
- After setting :password_confirmation to ‹nil›, then setting :password
75
- to ‹"any value"›, the matcher expected the Example to be invalid, but
76
- it was valid instead.
77
- MESSAGE
78
-
79
- expect(&assertion).to fail_with_message(message)
80
- end
81
- end
82
-
83
- context 'when the model does not have a confirmation attribute' do
84
- it 'raises an AttributeDoesNotExistError' do
85
- model = define_model(:example)
86
-
87
- assertion = lambda do
88
- expect(model.new).to validate_confirmation_of(:attribute_to_confirm)
89
- end
90
-
91
- message = <<-MESSAGE.rstrip
92
- The matcher attempted to set :attribute_to_confirm_confirmation on the
93
- Example to "some value", but that attribute does not exist.
94
- MESSAGE
95
-
96
- expect(&assertion).to raise_error(
97
- Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeDoesNotExistError,
98
- message
99
- )
100
- end
101
- end
102
-
103
- context 'when the model does not have the attribute under test' do
104
- it 'raises an AttributeDoesNotExistError' do
105
- model = define_model(:example, attribute_to_confirm_confirmation: :string)
106
-
107
- assertion = lambda do
108
- expect(model.new).to validate_confirmation_of(:attribute_to_confirm)
109
- end
110
-
111
- message = <<-MESSAGE.rstrip
112
- The matcher attempted to set :attribute_to_confirm on the Example to
113
- "different value", but that attribute does not exist.
114
- MESSAGE
115
-
116
- expect(&assertion).to raise_error(
117
- Shoulda::Matchers::ActiveModel::AllowValueMatcher::AttributeDoesNotExistError,
118
- message
119
- )
120
- end
121
- end
122
-
123
- context 'when the model has all attributes, but does not have the validation' do
124
- it 'fails with an appropriate failure message' do
125
- model = define_model(:example, attribute_to_confirm: :string) do
126
- attr_accessor :attribute_to_confirm_confirmation
127
- end
128
-
129
- assertion = lambda do
130
- expect(model.new).to validate_confirmation_of(:attribute_to_confirm)
131
- end
132
-
133
- message = <<-MESSAGE
134
- Expected Example to validate that :attribute_to_confirm_confirmation
135
- matches :attribute_to_confirm, but this could not be proved.
136
- After setting :attribute_to_confirm_confirmation to ‹"some value"›,
137
- then setting :attribute_to_confirm to ‹"different value"›, the matcher
138
- expected the Example to be invalid, but it was valid instead.
139
- MESSAGE
140
-
141
- expect(&assertion).to fail_with_message(message)
142
- end
143
- end
144
-
145
- context 'when both validation and matcher specify a custom message' do
146
- it 'passes when the expected and actual messages match' do
147
- builder = builder_for_record_validating_confirmation(message: 'custom')
148
- expect(builder.record).
149
- to validate_confirmation_of(builder.attribute_to_confirm).
150
- with_message(/custom/)
151
- end
152
-
153
- it 'fails when the expected and actual messages do not match' do
154
- builder = builder_for_record_validating_confirmation(message: 'custom')
155
- expect(builder.record).
156
- not_to validate_confirmation_of(builder.attribute_to_confirm).
157
- with_message(/wrong/)
158
- end
159
- end
160
-
161
- context 'when the validation specifies a message via i18n' do
162
- it 'passes' do
163
- builder = builder_for_record_validating_confirmation_with_18n_message
164
- expect(builder.record).
165
- to validate_confirmation_of(builder.attribute_to_confirm)
166
- end
167
- end
168
-
169
- def validation_matcher_scenario_args
170
- super.deep_merge(matcher_name: :validate_confirmation_of)
171
- end
172
- end
@@ -1,264 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher, type: :model do
4
- context 'an attribute which must be excluded from a range' do
5
- it 'accepts ensuring the correct range' do
6
- expect(validating_exclusion(in: 2..5)).
7
- to validate_exclusion_of(:attr).in_range(2..5)
8
- end
9
-
10
- it 'rejects if the given range spills past the top of the range in the validation' do
11
- expect(validating_exclusion(in: 2..5)).
12
- not_to validate_exclusion_of(:attr).in_range(2..6)
13
- end
14
-
15
- it 'rejects if the given range falls short of the top of the range in the validation' do
16
- expect(validating_exclusion(in: 2..5)).
17
- not_to validate_exclusion_of(:attr).in_range(2..4)
18
- end
19
-
20
- it 'rejects if the given range spills past the bottom of the range in the validation' do
21
- expect(validating_exclusion(in: 2..5)).
22
- not_to validate_exclusion_of(:attr).in_range(1..5)
23
- end
24
-
25
- it 'rejects if the given range falls short of the bottom of the range in the validation' do
26
- expect(validating_exclusion(in: 2..5)).
27
- not_to validate_exclusion_of(:attr).in_range(3..5)
28
- end
29
-
30
- it 'does not override the default message with a blank' do
31
- expect(validating_exclusion(in: 2..5)).
32
- to validate_exclusion_of(:attr).in_range(2..5).with_message(nil)
33
- end
34
-
35
- it_supports(
36
- 'ignoring_interference_by_writer',
37
- tests: {
38
- reject_if_qualified_but_changing_value_interferes: {
39
- model_name: 'Example',
40
- attribute_name: :attr,
41
- changing_values_with: :next_value,
42
- expected_message: <<-MESSAGE.strip
43
- Expected Example to validate that :attr lies outside the range ‹2› to
44
- ‹5›, but this could not be proved.
45
- After setting :attr to ‹1› -- which was read back as ‹2› -- the
46
- matcher expected the Example to be valid, but it was invalid instead,
47
- producing these validation errors:
48
-
49
- * attr: ["is reserved"]
50
-
51
- As indicated in the message above, :attr seems to be changing certain
52
- values as they are set, and this could have something to do with why
53
- this test is failing. If you've overridden the writer method for this
54
- attribute, then you may need to change it to make this test pass, or
55
- do something else entirely.
56
- MESSAGE
57
- },
58
- },
59
- model_creator: :active_model
60
- ) do
61
- def validation_matcher_scenario_args
62
- super.deep_merge(validation_options: { in: 2..5 })
63
- end
64
-
65
- def configure_validation_matcher(matcher)
66
- matcher.in_range(2..5)
67
- end
68
- end
69
-
70
- it 'fails when used in the negative' do
71
- assertion = lambda do
72
- expect(validating_exclusion(in: 2..5)).
73
- not_to validate_exclusion_of(:attr).in_range(2..5)
74
- end
75
-
76
- message = <<-MESSAGE
77
- Expected Example not to validate that :attr lies outside the range ‹2›
78
- to ‹5›, but this could not be proved.
79
- After setting :attr to ‹6›, the matcher expected the Example to be
80
- invalid, but it was valid instead.
81
- MESSAGE
82
-
83
- expect(&assertion).to fail_with_message(message)
84
- end
85
- end
86
-
87
- context 'an attribute which must be excluded from a range with excluded end' do
88
- it 'accepts ensuring the correct range' do
89
- expect(validating_exclusion(in: 2...5)).
90
- to validate_exclusion_of(:attr).in_range(2...5)
91
- end
92
-
93
- it 'rejects ensuring excluded value' do
94
- expect(validating_exclusion(in: 2...5)).
95
- not_to validate_exclusion_of(:attr).in_range(2...4)
96
- end
97
- end
98
-
99
- context 'an attribute with a custom validation message' do
100
- it 'accepts ensuring the correct range' do
101
- expect(validating_exclusion(in: 2..4, message: 'not good')).
102
- to validate_exclusion_of(:attr).in_range(2..4).with_message(/not good/)
103
- end
104
-
105
- it 'accepts ensuring the correct range with an interpolated variable in the message' do
106
- matcher = validating_exclusion(in: 2..4, message: '%{value} is not good')
107
- expect(matcher).
108
- to validate_exclusion_of(:attr).
109
- in_range(2..4).
110
- with_message(/^[234] is not good$/)
111
- end
112
- end
113
-
114
- context 'an attribute with custom range validations' do
115
- it 'accepts ensuring the correct range and messages' do
116
- model = custom_validation do
117
- if attr >= 2 && attr <= 5
118
- errors.add(:attr, 'should be out of this range')
119
- end
120
- end
121
-
122
- expect(model).to validate_exclusion_of(:attr).in_range(2..5).
123
- with_message(/should be out of this range/)
124
-
125
- model = custom_validation do
126
- if attr >= 2 && attr <= 4
127
- errors.add(:attr, 'should be out of this range')
128
- end
129
- end
130
-
131
- expect(model).to validate_exclusion_of(:attr).in_range(2...5).
132
- with_message(/should be out of this range/)
133
- end
134
-
135
- it 'has correct description' do
136
- matcher = validate_exclusion_of(:attr).in_range(1..10)
137
-
138
- expect(matcher.description).to eq(
139
- 'validate that :attr lies outside the range ‹1› to ‹10›'
140
- )
141
- end
142
- end
143
-
144
- context 'an attribute which must be excluded from an array' do
145
- it 'accepts with correct array' do
146
- expect(validating_exclusion(in: %w(one two))).
147
- to validate_exclusion_of(:attr).in_array(%w(one two))
148
- end
149
-
150
- it 'rejects when only part of array matches' do
151
- expect(validating_exclusion(in: %w(one two))).
152
- not_to validate_exclusion_of(:attr).in_array(%w(one wrong_value))
153
- end
154
-
155
- it 'rejects when array does not match at all' do
156
- expect(validating_exclusion(in: %w(one two))).
157
- not_to validate_exclusion_of(:attr).in_array(%w(cat dog))
158
- end
159
-
160
- context 'when there is one value' do
161
- it 'has correct description' do
162
- expect(validate_exclusion_of(:attr).in_array([true]).description).
163
- to eq 'validate that :attr is not ‹true›'
164
- end
165
- end
166
-
167
- context 'when there are two values' do
168
- it 'has correct description' do
169
- matcher = validate_exclusion_of(:attr).in_array([true, 'dog'])
170
-
171
- expect(matcher.description).to eq(
172
- 'validate that :attr is neither ‹true› nor ‹"dog"›'
173
- )
174
- end
175
- end
176
-
177
- context 'when there are three or more values' do
178
- it 'has correct description' do
179
- matcher = validate_exclusion_of(:attr).in_array([true, 'dog', 'cat'])
180
-
181
- expect(matcher.description).to eq(
182
- 'validate that :attr is neither ‹true›, ‹"dog"›, nor ‹"cat"›'
183
- )
184
- end
185
- end
186
-
187
- it_supports(
188
- 'ignoring_interference_by_writer',
189
- tests: {
190
- reject_if_qualified_but_changing_value_interferes: {
191
- model_name: 'Example',
192
- attribute_name: :attr,
193
- changing_values_with: :next_value,
194
- expected_message: <<-MESSAGE.strip
195
- Expected Example to validate that :attr is neither ‹"one"› nor ‹"two"›,
196
- but this could not be proved.
197
- After setting :attr to ‹"one"› -- which was read back as ‹"onf"› --
198
- the matcher expected the Example to be invalid, but it was valid
199
- instead.
200
-
201
- As indicated in the message above, :attr seems to be changing certain
202
- values as they are set, and this could have something to do with why
203
- this test is failing. If you've overridden the writer method for this
204
- attribute, then you may need to change it to make this test pass, or
205
- do something else entirely.
206
- MESSAGE
207
- },
208
- },
209
- model_creator: :active_model
210
- ) do
211
- def validation_matcher_scenario_args
212
- super.deep_merge(validation_options: { in: ['one', 'two'] })
213
- end
214
-
215
- def configure_validation_matcher(matcher)
216
- matcher.in_array(['one', 'two'])
217
- end
218
- end
219
-
220
- it 'fails when used in the negative' do
221
- assertion = lambda do
222
- expect(validating_exclusion(in: %w(one two))).
223
- not_to validate_exclusion_of(:attr).in_array(%w(one two))
224
- end
225
-
226
- message = <<-MESSAGE
227
- Expected Example not to validate that :attr is neither ‹"one"› nor
228
- ‹"two"›, but this could not be proved.
229
- After setting :attr to ‹"two"›, the matcher expected the Example to be
230
- valid, but it was invalid instead, producing these validation errors:
231
-
232
- * attr: ["is reserved"]
233
- MESSAGE
234
-
235
- expect(&assertion).to fail_with_message(message)
236
- end
237
-
238
- def define_model_validating_exclusion(options)
239
- options = options.dup
240
- column_type = options.delete(:column_type) { :string }
241
- super options.merge(column_type: column_type)
242
- end
243
- end
244
-
245
- def define_model_validating_exclusion(options)
246
- options = options.dup
247
- attribute_name = options.delete(:attribute_name) { :attr }
248
- column_type = options.delete(:column_type) { :integer }
249
-
250
- define_model(:example, attribute_name => column_type) do |model|
251
- model.validates_exclusion_of(attribute_name, options)
252
- end
253
- end
254
-
255
- def validating_exclusion(options)
256
- define_model_validating_exclusion(options).new
257
- end
258
-
259
- alias_method :build_record_validating_exclusion, :validating_exclusion
260
-
261
- def validation_matcher_scenario_args
262
- super.deep_merge(matcher_name: :validate_exclusion_of)
263
- end
264
- end