shoulda-matchers 3.1.0 → 5.2.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 (288) hide show
  1. checksums.yaml +5 -5
  2. data/{MIT-LICENSE → LICENSE} +1 -1
  3. data/README.md +407 -232
  4. data/docs/errors/NonCaseSwappableValueError.md +2 -2
  5. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +7 -80
  6. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +4 -3
  7. data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
  8. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +36 -30
  9. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +8 -10
  10. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +7 -9
  11. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +18 -15
  12. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +3 -2
  13. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +3 -3
  14. data/lib/shoulda/matchers/action_controller/route_matcher.rb +88 -29
  15. data/lib/shoulda/matchers/action_controller/route_params.rb +2 -2
  16. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +4 -4
  17. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -3
  18. data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
  19. data/lib/shoulda/matchers/action_controller.rb +2 -0
  20. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
  21. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -9
  22. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
  23. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
  24. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
  25. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +42 -39
  26. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
  27. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +52 -26
  28. data/lib/shoulda/matchers/active_model/helpers.rb +2 -2
  29. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -30
  30. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +2 -1
  31. data/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
  32. data/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
  33. data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
  34. data/lib/shoulda/matchers/active_model/qualifiers.rb +2 -0
  35. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +30 -6
  36. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +8 -3
  37. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +31 -16
  38. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +52 -16
  39. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +137 -84
  40. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +159 -46
  41. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +130 -66
  42. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +251 -24
  43. data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +12 -9
  44. data/lib/shoulda/matchers/active_model/validation_matcher.rb +38 -6
  45. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
  46. data/lib/shoulda/matchers/active_model/validator.rb +4 -9
  47. data/lib/shoulda/matchers/active_model.rb +3 -5
  48. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +10 -7
  49. data/lib/shoulda/matchers/active_record/association_matcher.rb +386 -111
  50. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
  51. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
  52. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
  53. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
  54. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +14 -15
  55. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +30 -8
  56. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +34 -11
  57. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +69 -0
  58. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
  59. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +74 -0
  60. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
  61. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
  62. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +458 -42
  63. data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +185 -0
  64. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +63 -23
  65. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +164 -48
  66. data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +106 -0
  67. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +13 -11
  68. data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
  69. data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
  70. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +18 -18
  71. data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
  72. data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
  73. data/lib/shoulda/matchers/active_record/uniqueness.rb +1 -1
  74. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +430 -200
  75. data/lib/shoulda/matchers/active_record.rb +28 -20
  76. data/lib/shoulda/matchers/configuration.rb +12 -1
  77. data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
  78. data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
  79. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
  80. data/lib/shoulda/matchers/doublespeak/object_double.rb +6 -2
  81. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
  82. data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
  83. data/lib/shoulda/matchers/doublespeak.rb +2 -1
  84. data/lib/shoulda/matchers/error.rb +1 -1
  85. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +109 -29
  86. data/lib/shoulda/matchers/independent.rb +2 -2
  87. data/lib/shoulda/matchers/integrations/configuration.rb +8 -4
  88. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
  89. data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
  90. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
  91. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
  92. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
  93. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
  94. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
  95. data/lib/shoulda/matchers/rails_shim.rb +172 -51
  96. data/lib/shoulda/matchers/routing.rb +2 -2
  97. data/lib/shoulda/matchers/util/word_wrap.rb +17 -12
  98. data/lib/shoulda/matchers/util.rb +39 -5
  99. data/lib/shoulda/matchers/version.rb +1 -1
  100. data/lib/shoulda/matchers/warn.rb +4 -3
  101. data/shoulda-matchers.gemspec +33 -15
  102. metadata +31 -338
  103. data/.gitignore +0 -12
  104. data/.hound.yml +0 -3
  105. data/.hound_config/ruby.yml +0 -12
  106. data/.travis.yml +0 -19
  107. data/.yardopts +0 -10
  108. data/Appraisals +0 -73
  109. data/CONTRIBUTING.md +0 -101
  110. data/Gemfile +0 -15
  111. data/Gemfile.lock +0 -70
  112. data/NEWS.md +0 -986
  113. data/Rakefile +0 -39
  114. data/custom_plan.rb +0 -88
  115. data/doc_config/gh-pages/index.html.erb +0 -9
  116. data/doc_config/yard/setup.rb +0 -22
  117. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  118. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  119. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -62
  120. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  121. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  122. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -32
  123. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  124. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  125. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -298
  126. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  127. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  128. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  129. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -8
  130. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  131. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  132. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  133. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  134. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  135. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  136. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  137. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  138. data/gemfiles/4.0.0.gemfile +0 -38
  139. data/gemfiles/4.0.0.gemfile.lock +0 -223
  140. data/gemfiles/4.0.1.gemfile +0 -38
  141. data/gemfiles/4.0.1.gemfile.lock +0 -225
  142. data/gemfiles/4.1.gemfile +0 -38
  143. data/gemfiles/4.1.gemfile.lock +0 -220
  144. data/gemfiles/4.2.gemfile +0 -38
  145. data/gemfiles/4.2.gemfile.lock +0 -243
  146. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
  147. data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +0 -37
  148. data/script/SUPPORTED_VERSIONS +0 -1
  149. data/script/install_gems_in_all_appraisals +0 -14
  150. data/script/run_all_tests +0 -14
  151. data/script/update_gem_in_all_appraisals +0 -15
  152. data/script/update_gems_in_all_appraisals +0 -14
  153. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  154. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  155. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  156. data/spec/acceptance/rails_integration_spec.rb +0 -156
  157. data/spec/acceptance_spec_helper.rb +0 -23
  158. data/spec/doublespeak_spec_helper.rb +0 -2
  159. data/spec/report_warnings.rb +0 -7
  160. data/spec/spec_helper.rb +0 -21
  161. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  162. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  163. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  164. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  165. data/spec/support/acceptance/helpers/command_helpers.rb +0 -55
  166. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  167. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  168. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  169. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  170. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  171. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  172. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  173. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  174. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  175. data/spec/support/acceptance/helpers.rb +0 -31
  176. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  177. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  178. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  179. data/spec/support/tests/bundle.rb +0 -94
  180. data/spec/support/tests/command_runner.rb +0 -230
  181. data/spec/support/tests/current_bundle.rb +0 -61
  182. data/spec/support/tests/database.rb +0 -28
  183. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  184. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  185. data/spec/support/tests/database_configuration.rb +0 -33
  186. data/spec/support/tests/database_configuration_registry.rb +0 -28
  187. data/spec/support/tests/filesystem.rb +0 -100
  188. data/spec/support/tests/version.rb +0 -45
  189. data/spec/support/unit/active_record/create_table.rb +0 -54
  190. data/spec/support/unit/attribute.rb +0 -47
  191. data/spec/support/unit/capture.rb +0 -40
  192. data/spec/support/unit/change_value.rb +0 -111
  193. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  194. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  195. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  196. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  197. data/spec/support/unit/helpers/active_model_versions.rb +0 -28
  198. data/spec/support/unit/helpers/active_record_versions.rb +0 -24
  199. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  200. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  201. data/spec/support/unit/helpers/class_builder.rb +0 -90
  202. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  203. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  204. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  205. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  206. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  207. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  208. data/spec/support/unit/helpers/model_builder.rb +0 -114
  209. data/spec/support/unit/helpers/rails_versions.rb +0 -28
  210. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  211. data/spec/support/unit/i18n.rb +0 -7
  212. data/spec/support/unit/load_environment.rb +0 -12
  213. data/spec/support/unit/matchers/deprecate.rb +0 -60
  214. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  215. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -62
  216. data/spec/support/unit/matchers/print_warning_including.rb +0 -59
  217. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  218. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  219. data/spec/support/unit/model_creators/active_model.rb +0 -39
  220. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  221. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  222. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  223. data/spec/support/unit/model_creators/active_record.rb +0 -43
  224. data/spec/support/unit/model_creators/basic.rb +0 -97
  225. data/spec/support/unit/model_creators.rb +0 -19
  226. data/spec/support/unit/rails_application.rb +0 -126
  227. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  228. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -51
  229. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  230. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  231. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  232. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  233. data/spec/support/unit/validation_matcher_scenario.rb +0 -62
  234. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  235. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  236. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -592
  237. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  238. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  239. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  240. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  241. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  242. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  243. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  244. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  245. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  246. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  247. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
  248. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -823
  249. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  250. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  251. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  252. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -266
  253. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -91
  254. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -149
  255. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -207
  256. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1015
  257. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -288
  258. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1837
  259. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -380
  260. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  261. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1242
  262. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  263. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -168
  264. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  265. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  266. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  267. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  268. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1418
  269. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  270. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  271. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  272. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  273. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  274. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  275. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -80
  276. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  277. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  278. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -517
  279. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -242
  280. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  281. data/spec/unit_spec_helper.rb +0 -46
  282. data/spec/warnings_spy/filesystem.rb +0 -45
  283. data/spec/warnings_spy/partitioner.rb +0 -36
  284. data/spec/warnings_spy/reader.rb +0 -53
  285. data/spec/warnings_spy/reporter.rb +0 -88
  286. data/spec/warnings_spy.rb +0 -64
  287. data/tasks/documentation.rb +0 -199
  288. data/zeus.json +0 -11
@@ -1,28 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::FilterParamMatcher, type: :controller do
4
- it 'accepts filtering a filtered parameter' do
5
- filter(:secret)
6
-
7
- expect(nil).to filter_param(:secret)
8
- end
9
-
10
- it 'accepts filtering a parameter matching a filtered regex' do
11
- filter(/(?!tip)pin(?!g)/)
12
-
13
- expect(nil).to filter_param(:pin)
14
- end
15
-
16
- it 'rejects filtering an unfiltered parameter' do
17
- filter(:secret)
18
- matcher = filter_param(:other)
19
-
20
- expect(matcher.matches?(nil)).to eq false
21
-
22
- expect(matcher.failure_message).to match(/Expected other to be filtered.*secret/)
23
- end
24
-
25
- def filter(param)
26
- Rails.application.config.filter_parameters = [param]
27
- end
28
- end
@@ -1,592 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::PermitMatcher, type: :controller do
4
- shared_examples 'basic tests' do
5
- it 'accepts a subset of the permitted attributes' do
6
- define_controller_with_strong_parameters(action: :create) do |ctrl|
7
- params_with_conditional_require(ctrl.params).permit(:name, :age)
8
- end
9
-
10
- expect(controller).to permit_with_conditional_slice_of_params(
11
- permit(:name).for(:create)
12
- )
13
- end
14
-
15
- it 'accepts all of the permitted attributes' do
16
- define_controller_with_strong_parameters(action: :create) do |ctrl|
17
- params_with_conditional_require(ctrl.params).permit(:name, :age)
18
- end
19
-
20
- expect(controller).to permit_with_conditional_slice_of_params(
21
- permit(:name, :age).for(:create)
22
- )
23
- end
24
-
25
- it 'rejects attributes that have not been permitted' do
26
- define_controller_with_strong_parameters(action: :create) do |ctrl|
27
- params_with_conditional_require(ctrl.params).permit(:name)
28
- end
29
-
30
- expect(controller).not_to permit_with_conditional_slice_of_params(
31
- permit(:name, :admin).for(:create)
32
- )
33
- end
34
-
35
- it 'rejects when #permit has not been called' do
36
- define_controller_with_strong_parameters(action: :create)
37
-
38
- expect(controller).not_to permit_with_conditional_slice_of_params(
39
- permit(:name).for(:create)
40
- )
41
- end
42
-
43
- it 'tracks multiple calls to #permit for different subparameters' do
44
- sets_of_attributes = [
45
- [:eta, :diner_id],
46
- [:phone_number, :address_1, :address_2, :city, :state, :zip]
47
- ]
48
-
49
- define_controller_with_strong_parameters(action: :create) do |ctrl|
50
- params_with_conditional_require(ctrl.params, :order).
51
- permit(sets_of_attributes[0])
52
-
53
- params_with_conditional_require(ctrl.params, :diner).
54
- permit(sets_of_attributes[1])
55
- end
56
-
57
- expect(controller).to permit_with_conditional_slice_of_params(
58
- permit(*sets_of_attributes[0]).for(:create),
59
- all_params: [:order, :diner],
60
- selected_param: :order
61
- )
62
-
63
- expect(controller).to permit_with_conditional_slice_of_params(
64
- permit(*sets_of_attributes[1]).for(:create),
65
- all_params: [:order, :diner],
66
- selected_param: :diner
67
- )
68
- end
69
- end
70
-
71
- it 'requires an action' do
72
- assertion = -> { expect(controller).to permit(:name) }
73
-
74
- define_controller_with_strong_parameters
75
-
76
- expect(&assertion).to raise_error(described_class::ActionNotDefinedError)
77
- end
78
-
79
- it 'requires a verb for a non-restful action' do
80
- define_controller_with_strong_parameters
81
-
82
- assertion = lambda do
83
- expect(controller).to permit(:name).for(:authorize)
84
- end
85
-
86
- expect(&assertion).to raise_error(described_class::VerbNotDefinedError)
87
- end
88
-
89
- context 'when operating on the entire params hash' do
90
- include_context 'basic tests' do
91
- def permit_with_conditional_slice_of_params(permit, options = {})
92
- permit
93
- end
94
-
95
- def params_with_conditional_require(params, *filters)
96
- params
97
- end
98
- end
99
- end
100
-
101
- context 'when operating on a slice of the params hash' do
102
- include_context 'basic tests' do
103
- def permit_with_conditional_slice_of_params(
104
- permit,
105
- all_params: [:user],
106
- selected_param: :user
107
- )
108
- params = all_params.reduce({}) do |hash, param|
109
- hash.merge(param => { any: 'value' })
110
- end
111
-
112
- permit.add_params(params).on(selected_param)
113
- end
114
-
115
- def params_with_conditional_require(params, *filters)
116
- if filters.none?
117
- filters = [:user]
118
- end
119
-
120
- params.require(*filters)
121
- end
122
- end
123
-
124
- it 'rejects if asserting that parameters were not permitted, but on the wrong slice' do
125
- define_controller_with_strong_parameters(action: :create) do
126
- params.require(:order).permit(:eta, :diner_id)
127
- end
128
-
129
- expect(controller).
130
- not_to permit(:eta, :diner_id).
131
- for(:create, params: { order: { some: 'value' } }).
132
- on(:something_else)
133
- end
134
-
135
- it 'tracks multiple calls to #permit for the same subparameter' do
136
- define_controller_with_strong_parameters(action: :create) do
137
- params.require(:foo).permit(:bar)
138
- params.require(:foo).permit(:baz)
139
- end
140
-
141
- params = {
142
- foo: {
143
- bar: 'some value',
144
- baz: 'some value'
145
- }
146
- }
147
- expect(controller).
148
- to permit(:bar).
149
- on(:foo).
150
- for(:create, params: params)
151
- expect(controller).
152
- to permit(:baz).
153
- on(:foo).
154
- for(:create, params: params)
155
- end
156
- end
157
-
158
- it 'can be used more than once in the same test' do
159
- define_controller_with_strong_parameters(action: :create) do
160
- params.permit(:name)
161
- end
162
-
163
- expect(controller).to permit(:name).for(:create)
164
- expect(controller).not_to permit(:admin).for(:create)
165
- end
166
-
167
- it 'allows extra parameters to be provided if the route requires them' do
168
- options = {
169
- controller_name: 'Posts',
170
- action: :show,
171
- routes: -> { get '/posts/:slug', to: 'posts#show' }
172
- }
173
-
174
- define_controller_with_strong_parameters(options) do
175
- params.permit(:name)
176
- end
177
-
178
- expect(controller).
179
- to permit(:name).
180
- for(:show, verb: :get, params: { slug: 'foo' })
181
- end
182
-
183
- it 'works with #update specifically' do
184
- define_controller_with_strong_parameters(action: :update) do
185
- params.permit(:name)
186
- end
187
-
188
- expect(controller).
189
- to permit(:name).
190
- for(:update, params: { id: 1 })
191
- end
192
-
193
- describe '#matches?' do
194
- it 'does not raise an error when #fetch was used instead of #require (issue #495)' do
195
- matcher = permit(:eta, :diner_id).for(:create)
196
- matching = -> { matcher.matches?(controller) }
197
-
198
- define_controller_with_strong_parameters(action: :create) do
199
- params.fetch(:order, {}).permit(:eta, :diner_id)
200
- end
201
-
202
- expect(&matching).not_to raise_error
203
- end
204
-
205
- context 'stubbing params on the controller' do
206
- it 'still allows the original params hash to be modified and accessed prior to the call to #require' do
207
- actual_user_params = nil
208
- actual_foo_param = nil
209
- matcher = permit(:name).for(
210
- :create,
211
- params: { user: { some: 'params' } }
212
- )
213
-
214
- define_controller_with_strong_parameters(action: :create) do
215
- params[:foo] = 'bar'
216
- actual_foo_param = params[:foo]
217
- actual_user_params = params[:user]
218
-
219
- params.permit(:name)
220
- end
221
-
222
- matcher.matches?(controller)
223
-
224
- expect(actual_user_params).to eq('some' => 'params')
225
- expect(actual_foo_param).to eq 'bar'
226
- end
227
-
228
- it 'still allows #require to return a slice of the params' do
229
- expected_user_params = { 'foo' => 'bar' }
230
- actual_user_params = nil
231
- matcher = permit(:name).for(
232
- :update,
233
- params: { id: 1, user: expected_user_params }
234
- )
235
-
236
- define_controller_with_strong_parameters(action: :update) do
237
- actual_user_params = params.require(:user)
238
- begin
239
- actual_user_params.permit(:name)
240
- rescue
241
- end
242
- end
243
-
244
- matcher.matches?(controller)
245
-
246
- expect(actual_user_params).to eq expected_user_params
247
- end
248
-
249
- it 'does not permanently stub the params hash' do
250
- matcher = permit(:name).for(:create)
251
- params_access = -> { controller.params.require(:user) }
252
-
253
- define_controller_with_strong_parameters(action: :create)
254
-
255
- matcher.matches?(controller)
256
-
257
- expect(&params_access).
258
- to raise_error(::ActionController::ParameterMissing)
259
- end
260
-
261
- it 'prevents permanently stubbing params on error' do
262
- matcher = permit(:name).for(:create)
263
- params_access = -> { controller.params.require(:user) }
264
-
265
- define_controller_raising_exception
266
-
267
- begin
268
- matcher.matches?(controller)
269
- rescue simulated_error_class
270
- end
271
-
272
- expect(&params_access).
273
- to raise_error(::ActionController::ParameterMissing)
274
- end
275
- end
276
- end
277
-
278
- describe '#description' do
279
- it 'returns the correct string' do
280
- options = { action: :create, method: :post }
281
-
282
- define_controller_with_strong_parameters(options) do
283
- params.permit(:name, :age)
284
- end
285
-
286
- matcher = described_class.new([:name, :age, :height]).for(:create)
287
- expect(matcher.description).to eq(
288
- '(for POST #create) restrict parameters to :name, :age, and :height'
289
- )
290
- end
291
-
292
- context 'when a verb is specified' do
293
- it 'returns the correct string' do
294
- options = { action: :some_action }
295
-
296
- define_controller_with_strong_parameters(options) do
297
- params.permit(:name, :age)
298
- end
299
-
300
- matcher = described_class.
301
- new([:name]).
302
- for(:some_action, verb: :put)
303
- expect(matcher.description).to eq(
304
- '(for PUT #some_action) restrict parameters to :name'
305
- )
306
- end
307
- end
308
- end
309
-
310
- describe 'positive failure message' do
311
- context 'when no parameters were permitted' do
312
- it 'returns the correct message' do
313
- define_controller_with_strong_parameters(action: :create)
314
-
315
- assertion = lambda do
316
- expect(@controller).
317
- to permit(:name, :age, :city, :country).
318
- for(:create)
319
- end
320
-
321
- message =
322
- 'Expected POST #create to restrict parameters to ' +
323
- ":name, :age, :city, and :country,\n" +
324
- 'but it did not restrict any parameters.'
325
-
326
- expect(&assertion).to fail_with_message(message)
327
- end
328
- end
329
-
330
- context 'when some, but not all, parameters were permitted' do
331
- it 'returns the correct message, including missing attributes' do
332
- define_controller_with_strong_parameters(action: :create) do
333
- params.permit(:name, :age)
334
- end
335
-
336
- assertion = lambda do
337
- expect(@controller).
338
- to permit(:name, :age, :city, :country).
339
- for(:create)
340
- end
341
-
342
- message =
343
- 'Expected POST #create to restrict parameters to ' +
344
- ":name, :age, :city, and :country,\n" +
345
- 'but the restricted parameters were :name and :age instead.'
346
-
347
- expect(&assertion).to fail_with_message(message)
348
- end
349
- end
350
-
351
- context 'qualified with #on' do
352
- context 'when the subparameter was never required' do
353
- it 'returns the correct message' do
354
- define_controller_with_strong_parameters(action: :create) do
355
- params.permit(:name, :age)
356
- end
357
-
358
- assertion = lambda do
359
- expect(@controller).
360
- to permit(:name, :age, :city, :country).
361
- for(:create).
362
- on(:person)
363
- end
364
-
365
- message =
366
- 'Expected POST #create to restrict parameters on :person to ' +
367
- ":name, :age, :city, and :country,\n" +
368
- 'but it did not restrict any parameters.'
369
-
370
- expect(&assertion).to fail_with_message(message)
371
- end
372
- end
373
-
374
- context 'when the subparameter was required' do
375
- context 'but no parameters were permitted' do
376
- it 'returns the correct message' do
377
- define_controller_with_strong_parameters(action: :create) do
378
- params.require(:person)
379
- end
380
-
381
- assertion = lambda do
382
- params = {
383
- person: {
384
- name: 'some name',
385
- age: 'some age'
386
- }
387
- }
388
- expect(@controller).
389
- to permit(:name, :age, :city, :country).
390
- for(:create, params: params).
391
- on(:person)
392
- end
393
-
394
- message =
395
- 'Expected POST #create to restrict parameters on :person to ' +
396
- ":name, :age, :city, and :country,\n" +
397
- 'but it did not restrict any parameters.'
398
-
399
- expect(&assertion).to fail_with_message(message)
400
- end
401
- end
402
-
403
- context 'but some, but not all, parameters were permitted' do
404
- it 'returns the correct message' do
405
- define_controller_with_strong_parameters(action: :create) do
406
- params.require(:person).permit(:name, :age)
407
- end
408
-
409
- assertion = lambda do
410
- params = {
411
- person: {
412
- name: 'some name',
413
- age: 'some age'
414
- }
415
- }
416
- expect(@controller).
417
- to permit(:name, :age, :city, :country).
418
- for(:create, params: params).
419
- on(:person)
420
- end
421
-
422
- message =
423
- 'Expected POST #create to restrict parameters on :person to ' +
424
- ":name, :age, :city, and :country,\n" +
425
- 'but the restricted parameters were :name and :age instead.'
426
-
427
- expect(&assertion).to fail_with_message(message)
428
- end
429
- end
430
- end
431
- end
432
- end
433
-
434
- describe 'negative failure message' do
435
- it 'returns the correct message' do
436
- define_controller_with_strong_parameters(action: :create) do
437
- params.permit(:name, :age, :city, :country)
438
- end
439
-
440
- assertion = lambda do
441
- expect(@controller).
442
- not_to permit(:name, :age, :city, :country).
443
- for(:create)
444
- end
445
-
446
- message =
447
- 'Expected POST #create not to restrict parameters to ' +
448
- ":name, :age, :city, and :country,\n" +
449
- 'but it did.'
450
-
451
- expect(&assertion).to fail_with_message(message)
452
- end
453
-
454
- context 'qualified with #on' do
455
- it 'returns the correct message' do
456
- define_controller_with_strong_parameters(action: :create) do
457
- params.require(:person).permit(:name, :age)
458
- end
459
-
460
- assertion = lambda do
461
- params = {
462
- person: {
463
- name: 'some name',
464
- age: 'some age'
465
- }
466
- }
467
- expect(@controller).
468
- not_to permit(:name, :age).
469
- for(:create, params: params).
470
- on(:person)
471
- end
472
-
473
- message =
474
- 'Expected POST #create not to restrict parameters on :person to ' +
475
- ":name and :age,\n" +
476
- 'but it did.'
477
-
478
- expect(&assertion).to fail_with_message(message)
479
- end
480
- end
481
- end
482
-
483
- describe '#for' do
484
- context 'when given :create' do
485
- it 'POSTs to the controller' do
486
- controller = ActionController::Base.new
487
- context = build_context
488
- matcher = permit(:name).for(:create).in_context(context)
489
-
490
- matcher.matches?(controller)
491
-
492
- expect(context).to have_received(:post).with(:create, {})
493
- end
494
- end
495
-
496
- context 'when given :update' do
497
- if rails_gte_4_1?
498
- it 'PATCHes to the controller' do
499
- controller = ActionController::Base.new
500
- context = build_context
501
- matcher = permit(:name).for(:update).in_context(context)
502
-
503
- matcher.matches?(controller)
504
-
505
- expect(context).to have_received(:patch).with(:update, {})
506
- end
507
- else
508
- it 'PUTs to the controller' do
509
- controller = ActionController::Base.new
510
- context = build_context
511
- matcher = permit(:name).for(:update).in_context(context)
512
-
513
- matcher.matches?(controller)
514
-
515
- expect(context).to have_received(:put).with(:update, {})
516
- end
517
- end
518
- end
519
-
520
- context 'when given a custom action and verb' do
521
- it 'calls the action with the verb' do
522
- controller = ActionController::Base.new
523
- context = build_context
524
- matcher = permit(:name).
525
- for(:hide, verb: :delete).
526
- in_context(context)
527
-
528
- matcher.matches?(controller)
529
-
530
- expect(context).to have_received(:delete).with(:hide, {})
531
- end
532
- end
533
- end
534
-
535
- let(:simulated_error_class) do
536
- Class.new(StandardError)
537
- end
538
-
539
- def define_controller_with_strong_parameters(options = {}, &action_body)
540
- model_name = options.fetch(:model_name, 'User')
541
- controller_name = options.fetch(:controller_name, 'UsersController')
542
- collection_name = controller_name.
543
- to_s.sub(/Controller$/, '').underscore.
544
- to_sym
545
- action_name = options.fetch(:action, :some_action)
546
- routes = options.fetch(:routes, -> { resources collection_name })
547
-
548
- define_model(model_name)
549
-
550
- controller_class = define_controller(controller_name) do
551
- define_method action_name do
552
- if action_body
553
- if action_body.arity == 0
554
- instance_eval(&action_body)
555
- else
556
- action_body.call(self)
557
- end
558
- end
559
-
560
- render nothing: true
561
- end
562
- end
563
-
564
- setup_rails_controller_test(controller_class)
565
-
566
- define_routes(&routes)
567
-
568
- controller_class
569
- end
570
-
571
- def define_controller_raising_exception
572
- _simulated_error_class = simulated_error_class
573
-
574
- controller_class = define_controller('Examples') do
575
- define_method :create do
576
- raise _simulated_error_class
577
- end
578
- end
579
-
580
- setup_rails_controller_test(controller_class)
581
-
582
- define_routes do
583
- get 'examples', to: 'examples#create'
584
- end
585
-
586
- controller_class
587
- end
588
-
589
- def build_context
590
- double('context', post: nil, put: nil, patch: nil, delete: nil)
591
- end
592
- end
@@ -1,42 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::RedirectToMatcher, type: :controller do
4
- context 'a controller that redirects' do
5
- it 'accepts redirecting to that url' do
6
- expect(controller_redirecting_to('/some/url')).to redirect_to('/some/url')
7
- end
8
-
9
- it 'rejects redirecting to a different url' do
10
- expect(controller_redirecting_to('/some/url')).
11
- not_to redirect_to('/some/other/url')
12
- end
13
-
14
- it 'accepts redirecting to that url in a block' do
15
- expect(controller_redirecting_to('/some/url')).
16
- to redirect_to('somewhere') { '/some/url' }
17
- end
18
-
19
- it 'rejects redirecting to a different url in a block' do
20
- expect(controller_redirecting_to('/some/url')).
21
- not_to redirect_to('somewhere else') { '/some/other/url' }
22
- end
23
-
24
- def controller_redirecting_to(url)
25
- build_fake_response { redirect_to url }
26
- end
27
- end
28
-
29
- context 'a controller that does not redirect' do
30
- it 'rejects redirecting to a url' do
31
- controller = build_fake_response { render text: 'hello' }
32
-
33
- expect(controller).not_to redirect_to('/some/url')
34
- end
35
- end
36
-
37
- it 'provides the correct description when provided a block' do
38
- matcher = redirect_to('somewhere else') { '/some/other/url' }
39
-
40
- expect(matcher.description).to eq 'redirect to "somewhere else"'
41
- end
42
- end