shoulda-matchers 4.4.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +22 -0
  3. data/README.md +18 -18
  4. data/lib/shoulda/matchers.rb +12 -13
  5. data/lib/shoulda/matchers/action_controller.rb +13 -13
  6. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +4 -89
  7. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +3 -2
  8. data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
  9. data/lib/shoulda/matchers/action_controller/permit_matcher.rb +29 -27
  10. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -8
  11. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -8
  12. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +16 -13
  13. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +2 -1
  14. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -6
  15. data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
  16. data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
  17. data/lib/shoulda/matchers/active_model.rb +25 -15
  18. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +29 -36
  19. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
  20. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -5
  21. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
  22. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
  23. data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
  24. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
  25. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +51 -25
  26. data/lib/shoulda/matchers/active_model/helpers.rb +2 -2
  27. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +0 -5
  28. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -34
  29. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -1
  30. data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
  31. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +10 -2
  32. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +2 -2
  33. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +8 -7
  34. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +26 -25
  35. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +6 -6
  36. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +40 -27
  37. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +4 -4
  38. data/lib/shoulda/matchers/active_model/validation_matcher.rb +6 -8
  39. data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +2 -4
  40. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
  41. data/lib/shoulda/matchers/active_model/validator.rb +4 -9
  42. data/lib/shoulda/matchers/active_record.rb +26 -14
  43. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +6 -3
  44. data/lib/shoulda/matchers/active_record/association_matcher.rb +101 -48
  45. data/lib/shoulda/matchers/active_record/association_matchers.rb +0 -12
  46. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
  47. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
  48. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
  49. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
  50. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -9
  51. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +12 -7
  52. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +23 -5
  53. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +3 -3
  54. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
  55. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +4 -4
  56. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
  57. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
  58. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +18 -9
  59. data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +46 -8
  60. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +39 -17
  61. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
  62. data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +7 -7
  63. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +12 -10
  64. data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +11 -7
  65. data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +2 -0
  66. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +13 -9
  67. data/lib/shoulda/matchers/active_record/uniqueness.rb +4 -4
  68. data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
  69. data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
  70. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +78 -71
  71. data/lib/shoulda/matchers/doublespeak.rb +9 -9
  72. data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
  73. data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
  74. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
  75. data/lib/shoulda/matchers/doublespeak/object_double.rb +1 -1
  76. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
  77. data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
  78. data/lib/shoulda/matchers/error.rb +1 -1
  79. data/lib/shoulda/matchers/independent.rb +1 -0
  80. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +14 -16
  81. data/lib/shoulda/matchers/integrations.rb +6 -6
  82. data/lib/shoulda/matchers/integrations/configuration.rb +1 -1
  83. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
  84. data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
  85. data/lib/shoulda/matchers/integrations/test_frameworks.rb +2 -4
  86. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
  87. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
  88. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
  89. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
  90. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
  91. data/lib/shoulda/matchers/rails_shim.rb +5 -42
  92. data/lib/shoulda/matchers/util.rb +9 -2
  93. data/lib/shoulda/matchers/util/word_wrap.rb +7 -7
  94. data/lib/shoulda/matchers/version.rb +1 -1
  95. data/lib/shoulda/matchers/warn.rb +3 -3
  96. data/shoulda-matchers.gemspec +12 -9
  97. metadata +14 -14
  98. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50d63f547edcfe3f040aff155386def4cf30b3b17befc2e24a3b29f9933d6aba
4
- data.tar.gz: dc7066ab2357ddda9efe73ab7bfd547dae0a2b6c3180a4d68d3fb715708af500
3
+ metadata.gz: 319b0cb3944a37309b11169bd71ffddde2d6af35b262795e7c16466d6d2c497c
4
+ data.tar.gz: 22ac49d578766e24a18826bcde86443a09afa41c1cfc9ee7932f94f214623a36
5
5
  SHA512:
6
- metadata.gz: a112316adba7fa8458cc8b4aa404152cf3618705f232002dddc7b1004f99f69a9717961d4893cfaff50e7d802ae30ea7837e70104bc4a497c9b560982ab80831
7
- data.tar.gz: a732f1d0039ad911f35ee9f1d05a4cac8683232b253b42a59a8d6409ed285e292213bca8680e4c627f9fbd7ff27ba85dcc5d67a42885d571462456c385ec635a
6
+ metadata.gz: 05a067ef5aa288661855f6257a55ce887bdf19f6684cd965c145669815a3d432a236cd7fb88e21647d0251e4e971b6c45b03af04def19b5cefbef26279276d81
7
+ data.tar.gz: f06e9c331d39d82fd450332cb0b81e108852c7fac2a28927ada2fbccc11b31226206023f69eb6ecccd7dceaaca4c9b3410b818ed86babd3f7f37bb4c778013df
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2006-2021 Tammer Saleh and thoughtbot, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,14 +1,12 @@
1
- # Shoulda Matchers [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] [![Total Downloads][downloads-total]][rubygems] [![Downloads][downloads-badge]][rubygems] [![Hound][hound-badge]][hound]
1
+ # Shoulda Matchers [![Gem Version][version-badge]][rubygems] [![Build Status][github-actions-badge]][github-actions] [![Total Downloads][downloads-total]][rubygems] [![Downloads][downloads-badge]][rubygems]
2
2
 
3
3
  [version-badge]: https://img.shields.io/gem/v/shoulda-matchers.svg
4
4
  [rubygems]: https://rubygems.org/gems/shoulda-matchers
5
- [travis-badge]: https://img.shields.io/travis/thoughtbot/shoulda-matchers/master.svg
6
- [travis]: https://travis-ci.org/thoughtbot/shoulda-matchers
5
+ [github-actions-badge]: https://img.shields.io/github/workflow/status/thoughtbot/shoulda-matchers/Test
6
+ [github-actions]: https://github.com/thoughtbot/shoulda-matchers/actions
7
7
  [downloads-total]: https://img.shields.io/gem/dt/shoulda-matchers.svg
8
8
  [downloads-badge]: https://img.shields.io/gem/dtv/shoulda-matchers.svg
9
9
  [downloads-badge]: https://img.shields.io/gem/dtv/shoulda-matchers.svg
10
- [hound-badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
11
- [hound]: https://houndci.com
12
10
 
13
11
  [![shoulda-matchers][logo]][website]
14
12
 
@@ -24,7 +22,7 @@ complex, and error-prone.
24
22
  📖 **[Read the documentation for the latest version][rubydocs].**
25
23
  📢 **[See what's changed in recent versions][changelog].**
26
24
 
27
- [rubydocs]: http://matchers.shoulda.io/docs
25
+ [rubydocs]: https://matchers.shoulda.io/docs
28
26
  [changelog]: CHANGELOG.md
29
27
 
30
28
  ## Table of contents
@@ -57,7 +55,7 @@ Start by including `shoulda-matchers` in your Gemfile:
57
55
 
58
56
  ```ruby
59
57
  group :test do
60
- gem 'shoulda-matchers', '~> 4.0'
58
+ gem 'shoulda-matchers', '~> 5.0'
61
59
  end
62
60
  ```
63
61
 
@@ -385,7 +383,7 @@ about any of them, make sure to [consult the documentation][rubydocs]!
385
383
  tests your `belongs_to` associations.
386
384
  * **[define_enum_for](lib/shoulda/matchers/active_record/define_enum_for_matcher.rb)**
387
385
  tests usage of the `enum` macro.
388
- * **[have_and_belong_to_many](lib/shoulda/matchers/active_record/association_matcher.rb)**
386
+ * **[have_and_belong_to_many](lib/shoulda/matchers/active_record/association_matcher.rb#L827)**
389
387
  tests your `has_and_belongs_to_many` associations.
390
388
  * **[have_db_column](lib/shoulda/matchers/active_record/have_db_column_matcher.rb)**
391
389
  tests that the table that backs your model has a specific column.
@@ -393,11 +391,11 @@ about any of them, make sure to [consult the documentation][rubydocs]!
393
391
  tests that the table that backs your model has an index on a specific column.
394
392
  * **[have_implicit_order_column](lib/shoulda/matchers/active_record/have_implicit_order_column.rb)**
395
393
  tests usage of `implicit_order_column`.
396
- * **[have_many](lib/shoulda/matchers/active_record/association_matcher.rb)**
394
+ * **[have_many](lib/shoulda/matchers/active_record/association_matcher.rb#L328)**
397
395
  tests your `has_many` associations.
398
396
  * **[have_many_attached](lib/shoulda/matchers/active_record/have_attached_matcher.rb)**
399
397
  tests your `has_many_attached` associations.
400
- * **[have_one](lib/shoulda/matchers/active_record/association_matcher.rb)**
398
+ * **[have_one](lib/shoulda/matchers/active_record/association_matcher.rb#L598)**
401
399
  tests your `has_one` associations.
402
400
  * **[have_one_attached](lib/shoulda/matchers/active_record/have_attached_matcher.rb)**
403
401
  tests your `has_one_attached` associations.
@@ -432,11 +430,11 @@ about any of them, make sure to [consult the documentation][rubydocs]!
432
430
  makes assertions on the `session` hash.
433
431
  * **[set_flash](lib/shoulda/matchers/action_controller/set_flash_matcher.rb)**
434
432
  makes assertions on the `flash` hash.
435
- * **[use_after_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L79)**
433
+ * **[use_after_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L29)**
436
434
  tests that an `after_action` callback is defined in your controller.
437
- * **[use_around_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L129)**
435
+ * **[use_around_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L75)**
438
436
  tests that an `around_action` callback is defined in your controller.
439
- * **[use_before_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L54)**
437
+ * **[use_before_action](lib/shoulda/matchers/action_controller/callback_matcher.rb#L4)**
440
438
  tests that a `before_action` callback is defined in your controller.
441
439
 
442
440
  ### Routing matchers
@@ -470,17 +468,19 @@ machine, understanding the codebase, and creating a good pull request.
470
468
 
471
469
  ## Compatibility
472
470
 
473
- Shoulda Matchers is [tested][travis] and supported against Ruby 2.4+, Rails
474
- 4.2+, RSpec 3.x, and Minitest 5.x.
471
+ Shoulda Matchers is tested and supported against Ruby 2.6+, Rails
472
+ 5.2+, RSpec 3.x, and Minitest 5.x.
475
473
 
476
- For Ruby < 2.4 and Rails < 4.1 compatibility, please use [v3.1.3][v3.1.3].
474
+ - For Ruby < 2.4 and Rails < 4.1 compatibility, please use [v3.1.3][v3.1.3].
475
+ - For Ruby < 3.0 and Rails < 6.1 compatibility, please use [v4.5.1][v4.5.1].
477
476
 
478
477
  [v3.1.3]: https://github.com/thoughtbot/shoulda-matchers/tree/v3.1.3
478
+ [v4.5.1]: https://github.com/thoughtbot/shoulda-matchers/tree/v4.5.1
479
479
 
480
480
  ## Versioning
481
481
 
482
482
  Shoulda Matchers follows Semantic Versioning 2.0 as defined at
483
- <http://semver.org>.
483
+ <https://semver.org>.
484
484
 
485
485
  ## Team
486
486
 
@@ -492,7 +492,7 @@ Albuk][guialbuk].
492
492
 
493
493
  ## Copyright/License
494
494
 
495
- Shoulda Matchers is copyright © 2006-2020 Tammer Saleh and [thoughtbot,
495
+ Shoulda Matchers is copyright © 2006-2021 Tammer Saleh and [thoughtbot,
496
496
  inc][thoughtbot-website]. It is free and opensource software and may be
497
497
  redistributed under the terms specified in the [LICENSE](LICENSE) file.
498
498
 
@@ -1,22 +1,21 @@
1
1
  require 'shoulda/matchers/configuration'
2
+ require 'shoulda/matchers/doublespeak'
3
+ require 'shoulda/matchers/error'
4
+ require 'shoulda/matchers/independent'
5
+ require 'shoulda/matchers/integrations'
6
+ require 'shoulda/matchers/matcher_context'
7
+ require 'shoulda/matchers/rails_shim'
8
+ require 'shoulda/matchers/util'
2
9
  require 'shoulda/matchers/version'
3
10
  require 'shoulda/matchers/warn'
4
11
 
12
+ require 'shoulda/matchers/action_controller'
13
+ require 'shoulda/matchers/active_model'
14
+ require 'shoulda/matchers/active_record'
15
+ require 'shoulda/matchers/routing'
16
+
5
17
  module Shoulda
6
18
  module Matchers
7
- autoload :ActionController, 'shoulda/matchers/action_controller'
8
- autoload :ActiveModel, 'shoulda/matchers/active_model'
9
- autoload :ActiveRecord, 'shoulda/matchers/active_record'
10
- autoload :Doublespeak, 'shoulda/matchers/doublespeak'
11
- autoload :Error, 'shoulda/matchers/error'
12
- autoload :Independent, 'shoulda/matchers/independent'
13
- autoload :Integrations, 'shoulda/matchers/integrations'
14
- autoload :MatcherContext, 'shoulda/matchers/matcher_context'
15
- autoload :RailsShim, 'shoulda/matchers/rails_shim'
16
- autoload :Routing, 'shoulda/matchers/routing'
17
- autoload :Util, 'shoulda/matchers/util'
18
- autoload :WordWrap, 'shoulda/matchers/util/word_wrap'
19
-
20
19
  class << self
21
20
  # @private
22
21
  attr_accessor :assertion_exception_class
@@ -1,24 +1,24 @@
1
+ require 'shoulda/matchers/action_controller/filter_param_matcher'
2
+ require 'shoulda/matchers/action_controller/route_params'
3
+ require 'shoulda/matchers/action_controller/set_flash_matcher'
4
+ require 'shoulda/matchers/action_controller/render_with_layout_matcher'
1
5
  require 'shoulda/matchers/action_controller/respond_with_matcher'
6
+ require 'shoulda/matchers/action_controller/set_session_matcher'
2
7
  require 'shoulda/matchers/action_controller/route_matcher'
8
+ require 'shoulda/matchers/action_controller/redirect_to_matcher'
9
+ require 'shoulda/matchers/action_controller/render_template_matcher'
10
+ require 'shoulda/matchers/action_controller/rescue_from_matcher'
11
+ require 'shoulda/matchers/action_controller/callback_matcher'
12
+ require 'shoulda/matchers/action_controller/permit_matcher'
13
+ require 'shoulda/matchers/action_controller/set_session_or_flash_matcher'
14
+ require 'shoulda/matchers/action_controller/flash_store'
15
+ require 'shoulda/matchers/action_controller/session_store'
3
16
 
4
17
  module Shoulda
5
18
  module Matchers
6
19
  # This module provides matchers that are used to test behavior within
7
20
  # controllers.
8
21
  module ActionController
9
- autoload :CallbackMatcher, 'shoulda/matchers/action_controller/callback_matcher'
10
- autoload :FlashStore, 'shoulda/matchers/action_controller/flash_store'
11
- autoload :FilterParamMatcher, 'shoulda/matchers/action_controller/filter_param_matcher'
12
- autoload :PermitMatcher, 'shoulda/matchers/action_controller/permit_matcher'
13
- autoload :RedirectToMatcher, 'shoulda/matchers/action_controller/redirect_to_matcher'
14
- autoload :RenderTemplateMatcher, 'shoulda/matchers/action_controller/render_template_matcher'
15
- autoload :RenderWithLayoutMatcher, 'shoulda/matchers/action_controller/render_with_layout_matcher'
16
- autoload :RescueFromMatcher, 'shoulda/matchers/action_controller/rescue_from_matcher'
17
- autoload :RouteParams, 'shoulda/matchers/action_controller/route_params'
18
- autoload :SessionStore, 'shoulda/matchers/action_controller/session_store'
19
- autoload :SetFlashMatcher, 'shoulda/matchers/action_controller/set_flash_matcher'
20
- autoload :SetSessionMatcher, 'shoulda/matchers/action_controller/set_session_matcher'
21
- autoload :SetSessionOrFlashMatcher, 'shoulda/matchers/action_controller/set_session_or_flash_matcher'
22
22
  end
23
23
  end
24
24
  end
@@ -1,64 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  module ActionController
4
- # The `use_before_filter` matcher is used to test that a before_filter
5
- # callback is defined within your controller.
6
- #
7
- # class UsersController < ApplicationController
8
- # before_filter :authenticate_user!
9
- # end
10
- #
11
- # # RSpec
12
- # RSpec.describe UsersController, type: :controller do
13
- # it { should use_before_filter(:authenticate_user!) }
14
- # it { should_not use_before_filter(:prevent_ssl) }
15
- # end
16
- #
17
- # # Minitest (Shoulda)
18
- # class UsersControllerTest < ActionController::TestCase
19
- # should use_before_filter(:authenticate_user!)
20
- # should_not use_before_filter(:prevent_ssl)
21
- # end
22
- #
23
- # @note This method is only available when using shoulda-matchers under
24
- # Rails 4.x.
25
- # @return [CallbackMatcher]
26
- #
27
- if RailsShim.action_pack_lt_5?
28
- def use_before_filter(callback)
29
- CallbackMatcher.new(callback, :before, :filter)
30
- end
31
- end
32
-
33
- # The `use_after_filter` matcher is used to test that an after_filter
34
- # callback is defined within your controller.
35
- #
36
- # class IssuesController < ApplicationController
37
- # after_filter :log_activity
38
- # end
39
- #
40
- # # RSpec
41
- # RSpec.describe IssuesController, type: :controller do
42
- # it { should use_after_filter(:log_activity) }
43
- # it { should_not use_after_filter(:destroy_user) }
44
- # end
45
- #
46
- # # Minitest (Shoulda)
47
- # class IssuesControllerTest < ActionController::TestCase
48
- # should use_after_filter(:log_activity)
49
- # should_not use_after_filter(:destroy_user)
50
- # end
51
- #
52
- # @note This method is only available when using shoulda-matchers under
53
- # Rails 4.x.
54
- # @return [CallbackMatcher]
55
- #
56
- if RailsShim.action_pack_lt_5?
57
- def use_after_filter(callback)
58
- CallbackMatcher.new(callback, :after, :filter)
59
- end
60
- end
61
-
62
4
  # The `use_before_action` matcher is used to test that a before_action
63
5
  # callback is defined within your controller.
64
6
  #
@@ -109,35 +51,6 @@ module Shoulda
109
51
  CallbackMatcher.new(callback, :after, :action)
110
52
  end
111
53
 
112
- # The `use_around_filter` matcher is used to test that an around_filter
113
- # callback is defined within your controller.
114
- #
115
- # class ChangesController < ApplicationController
116
- # around_filter :wrap_in_transaction
117
- # end
118
- #
119
- # # RSpec
120
- # RSpec.describe ChangesController, type: :controller do
121
- # it { should use_around_filter(:wrap_in_transaction) }
122
- # it { should_not use_around_filter(:save_view_context) }
123
- # end
124
- #
125
- # # Minitest (Shoulda)
126
- # class ChangesControllerTest < ActionController::TestCase
127
- # should use_around_filter(:wrap_in_transaction)
128
- # should_not use_around_filter(:save_view_context)
129
- # end
130
- #
131
- # @note This method is only available when using shoulda-matchers under
132
- # Rails 4.x.
133
- # @return [CallbackMatcher]
134
- #
135
- if RailsShim.action_pack_lt_5?
136
- def use_around_filter(callback)
137
- CallbackMatcher.new(callback, :around, :filter)
138
- end
139
- end
140
-
141
54
  # The `use_around_action` matcher is used to test that an around_action
142
55
  # callback is defined within your controller.
143
56
  #
@@ -179,11 +92,13 @@ module Shoulda
179
92
  end
180
93
 
181
94
  def failure_message
182
- "Expected that #{controller_class.name} would have :#{method_name} as a #{kind}_#{callback_type}"
95
+ "Expected that #{controller_class.name} would have :#{method_name}"\
96
+ " as a #{kind}_#{callback_type}"
183
97
  end
184
98
 
185
99
  def failure_message_when_negated
186
- "Expected that #{controller_class.name} would not have :#{method_name} as a #{kind}_#{callback_type}"
100
+ "Expected that #{controller_class.name} would not have"\
101
+ " :#{method_name} as a #{kind}_#{callback_type}"
187
102
  end
188
103
 
189
104
  def description
@@ -31,12 +31,13 @@ module Shoulda
31
31
  @key = key
32
32
  end
33
33
 
34
- def matches?(controller)
34
+ def matches?(_controller)
35
35
  filters_key?
36
36
  end
37
37
 
38
38
  def failure_message
39
- "Expected #{@key} to be filtered; filtered keys: #{filtered_keys.join(', ')}"
39
+ "Expected #{@key} to be filtered; filtered keys:"\
40
+ " #{filtered_keys.join(', ')}"
40
41
  end
41
42
 
42
43
  def failure_message_when_negated
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/module/delegation'
1
2
  module Shoulda
2
3
  module Matchers
3
4
  module ActionController
@@ -34,10 +35,7 @@ module Shoulda
34
35
  expected_value === actual_value
35
36
  end
36
37
  end
37
-
38
- def empty?
39
- flash.empty?
40
- end
38
+ delegate :empty?, to: :flash
41
39
 
42
40
  def use_now!
43
41
  @use_now = true
@@ -209,7 +209,8 @@ module Shoulda
209
209
  attr_writer :stubbed_params
210
210
 
211
211
  def initialize(expected_permitted_parameter_names)
212
- @expected_permitted_parameter_names = expected_permitted_parameter_names
212
+ @expected_permitted_parameter_names =
213
+ expected_permitted_parameter_names
213
214
  @action = nil
214
215
  @verb = nil
215
216
  @request_params = {}
@@ -250,30 +251,29 @@ module Shoulda
250
251
  parameters_double_registry.register
251
252
 
252
253
  Doublespeak.with_doubles_activated do
253
- Shoulda::Matchers::RailsShim.make_controller_request(
254
- context,
255
- verb,
256
- action,
257
- request_params,
258
- )
254
+ params = { params: request_params }
255
+
256
+ context.__send__(verb, action, **params)
259
257
  end
260
258
 
261
259
  unpermitted_parameter_names.empty?
262
260
  end
263
261
 
264
262
  def failure_message
265
- "Expected #{verb.upcase} ##{action} to #{expectation},\nbut #{reality}."
263
+ "Expected #{verb.upcase} ##{action} to #{expectation},"\
264
+ "\nbut #{reality}."
266
265
  end
267
266
 
268
267
  def failure_message_when_negated
269
- "Expected #{verb.upcase} ##{action} not to #{expectation},\nbut it did."
268
+ "Expected #{verb.upcase} ##{action} not to #{expectation},"\
269
+ "\nbut it did."
270
270
  end
271
271
 
272
272
  protected
273
273
 
274
- attr_reader :controller, :double_collections_by_parameter_name, :action, :verb,
275
- :request_params, :expected_permitted_parameter_names, :context, :subparameter_name,
276
- :parameters_double_registry
274
+ attr_reader :controller, :double_collections_by_parameter_name, :action,
275
+ :verb, :request_params, :expected_permitted_parameter_names,
276
+ :context, :subparameter_name, :parameters_double_registry
277
277
 
278
278
  def expectation
279
279
  message = 'restrict parameters '
@@ -282,7 +282,8 @@ module Shoulda
282
282
  message << "on #{subparameter_name.inspect} "
283
283
  end
284
284
 
285
- message << 'to ' + format_parameter_names(expected_permitted_parameter_names)
285
+ message << 'to '\
286
+ "#{format_parameter_names(expected_permitted_parameter_names)}"
286
287
 
287
288
  message
288
289
  end
@@ -291,9 +292,9 @@ module Shoulda
291
292
  if actual_permitted_parameter_names.empty?
292
293
  'it did not restrict any parameters'
293
294
  else
294
- 'the restricted parameters were ' +
295
- format_parameter_names(actual_permitted_parameter_names) +
296
- ' instead'
295
+ 'the restricted parameters were '\
296
+ "#{format_parameter_names(actual_permitted_parameter_names)}"\
297
+ ' instead'
297
298
  end
298
299
  end
299
300
 
@@ -303,12 +304,12 @@ module Shoulda
303
304
 
304
305
  def actual_permitted_parameter_names
305
306
  @_actual_permitted_parameter_names ||= begin
306
- if subparameter_name
307
- options = { for: subparameter_name }
308
- else
309
- options = {}
310
- end
311
-
307
+ options =
308
+ if subparameter_name
309
+ { for: subparameter_name }
310
+ else
311
+ {}
312
+ end
312
313
  parameters_double_registry.permitted_parameter_names(options)
313
314
  end
314
315
  end
@@ -329,8 +330,8 @@ module Shoulda
329
330
 
330
331
  def default_verb
331
332
  case action
332
- when :create then :post
333
- when :update then RailsShim.verb_for_update
333
+ when :create then :post
334
+ when :update then RailsShim.verb_for_update
334
335
  end
335
336
  end
336
337
 
@@ -346,7 +347,7 @@ module Shoulda
346
347
 
347
348
  def register
348
349
  double_collection = Doublespeak.double_collection_for(
349
- ::ActionController::Parameters.singleton_class
350
+ ::ActionController::Parameters.singleton_class,
350
351
  )
351
352
  double_collection.register_proxy(:new).to_return do |call|
352
353
  params = call.return_value
@@ -389,7 +390,7 @@ module Shoulda
389
390
 
390
391
  if double_collections_by_parameter_name.key?(subparameter_name)
391
392
  self.class.permitted_parameter_names_within(
392
- double_collections_by_parameter_name[subparameter_name]
393
+ double_collections_by_parameter_name[subparameter_name],
393
394
  )
394
395
  else
395
396
  []
@@ -436,7 +437,8 @@ module Shoulda
436
437
  # @private
437
438
  class VerbNotDefinedError < StandardError
438
439
  def message
439
- 'You must specify an HTTP verb when using a non-RESTful action. For example: for(:authorize, verb: :post)'
440
+ 'You must specify an HTTP verb when using a non-RESTful action.'\
441
+ ' For example: for(:authorize, verb: :post)'
440
442
  end
441
443
  end
442
444
  end