giga-safe-box 0.0.1

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 (140) hide show
  1. checksums.yaml +7 -0
  2. data/giga-safe-box.gemspec +11 -0
  3. data/shoulda-matchers-8.0.1/LICENSE +22 -0
  4. data/shoulda-matchers-8.0.1/README.md +567 -0
  5. data/shoulda-matchers-8.0.1/docs/errors/NonCaseSwappableValueError.md +111 -0
  6. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/callback_matcher.rb +121 -0
  7. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +70 -0
  8. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/flash_store.rb +86 -0
  9. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/permit_matcher.rb +445 -0
  10. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +96 -0
  11. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb +84 -0
  12. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +145 -0
  13. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +115 -0
  14. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +148 -0
  15. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_matcher.rb +207 -0
  16. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_params.rb +62 -0
  17. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
  18. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +228 -0
  19. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_matcher.rb +163 -0
  20. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +107 -0
  21. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller.rb +24 -0
  22. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +45 -0
  23. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb +23 -0
  24. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +232 -0
  25. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +62 -0
  26. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +40 -0
  27. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +48 -0
  28. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_check.rb +14 -0
  29. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_setting.rb +14 -0
  30. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher.rb +695 -0
  31. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/comparison_matcher.rb +157 -0
  32. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +78 -0
  33. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/errors.rb +52 -0
  34. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +125 -0
  35. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/helpers.rb +37 -0
  36. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +45 -0
  37. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +67 -0
  38. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +45 -0
  39. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +44 -0
  40. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb +71 -0
  41. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb +53 -0
  42. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  43. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
  44. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
  45. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb +101 -0
  46. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +21 -0
  47. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers.rb +14 -0
  48. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +180 -0
  49. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +128 -0
  50. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_comparison_of_matcher.rb +567 -0
  51. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +185 -0
  52. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +272 -0
  53. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +664 -0
  54. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +575 -0
  55. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +711 -0
  56. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +428 -0
  57. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +62 -0
  58. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher.rb +195 -0
  59. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_message_finder.rb +63 -0
  60. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validator.rb +127 -0
  61. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model.rb +96 -0
  62. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +217 -0
  63. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matcher.rb +2134 -0
  64. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +74 -0
  65. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +62 -0
  66. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +41 -0
  67. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +105 -0
  68. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +101 -0
  69. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +89 -0
  70. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +142 -0
  71. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +71 -0
  72. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
  73. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +76 -0
  74. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +42 -0
  75. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +65 -0
  76. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  77. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +784 -0
  78. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/encrypt_matcher.rb +174 -0
  79. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_attached_matcher.rb +343 -0
  80. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +366 -0
  81. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +287 -0
  82. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +104 -0
  83. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +95 -0
  84. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
  85. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
  86. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/normalize_matcher.rb +151 -0
  87. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/serialize_matcher.rb +203 -0
  88. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/model.rb +58 -0
  89. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +39 -0
  90. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +49 -0
  91. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +55 -0
  92. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
  93. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1197 -0
  94. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record.rb +37 -0
  95. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/configuration.rb +31 -0
  96. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double.rb +103 -0
  97. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_collection.rb +60 -0
  98. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +31 -0
  99. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/method_call.rb +44 -0
  100. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/object_double.rb +43 -0
  101. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +32 -0
  102. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/stub_implementation.rb +31 -0
  103. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/world.rb +63 -0
  104. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak.rb +38 -0
  105. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/error.rb +29 -0
  106. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +15 -0
  107. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher.rb +540 -0
  108. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent.rb +11 -0
  109. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration.rb +70 -0
  110. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
  111. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
  112. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/action_controller.rb +33 -0
  113. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
  114. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
  115. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
  116. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/rails.rb +31 -0
  117. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/routing.rb +29 -0
  118. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries.rb +16 -0
  119. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/rails.rb +12 -0
  120. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/registry.rb +28 -0
  121. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
  122. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
  123. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
  124. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
  125. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
  126. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
  127. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
  128. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations.rb +43 -0
  129. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_collection.rb +99 -0
  130. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_context.rb +36 -0
  131. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/rails_shim.rb +190 -0
  132. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/routing.rb +10 -0
  133. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util/word_wrap.rb +211 -0
  134. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util.rb +110 -0
  135. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/version.rb +6 -0
  136. data/shoulda-matchers-8.0.1/lib/shoulda/matchers/warn.rb +28 -0
  137. data/shoulda-matchers-8.0.1/lib/shoulda/matchers.rb +25 -0
  138. data/shoulda-matchers-8.0.1/lib/shoulda-matchers.rb +1 -0
  139. data/shoulda-matchers-8.0.1/shoulda-matchers.gemspec +43 -0
  140. metadata +178 -0
@@ -0,0 +1,111 @@
1
+ # @title NonCaseSwappableValueError
2
+
3
+ # NonCaseSwappableValueError
4
+
5
+ This error is raised when using `validate_uniqueness_of`. This matcher, of
6
+ course, tests that an attribute disallows a non-unique value -- and what
7
+ constitutes as "unique" depends on whether the case-sensitivity of that value
8
+ matters. If it does matter -- meaning that the uniqueness validation in your
9
+ model isn't using `case_sensitive: false` and you haven't qualified the matcher
10
+ with `case_insensitive` -- then the matcher will run the following test:
11
+
12
+ > Creating first a record with a value of "A":
13
+ >
14
+ > * A new record with a value of "A" should not be valid (failing the uniqueness
15
+ > validation)
16
+ > * A new record with a value of "a" should be valid
17
+
18
+ The test value we're using is in this case "A", and this is what the matcher
19
+ will use if an existing record is not already present in the database. But if
20
+ a record already exists, then the matcher will use it as comparison -- it will
21
+ read the attribute under test off of the record and use its value. So a better
22
+ example might be:
23
+
24
+ > Given an existing record with a value:
25
+ >
26
+ > * A new record with the same value should not be valid (failing the uniqueness
27
+ > validation)
28
+ > * A new record with the same value, but where the case is swapped (using
29
+ > String#swapcase), should be valid
30
+
31
+ Now, what happens if an existing record is there, but the value being used is
32
+ not one whose case can be swapped, such as `"123"` or `"{-#%}"`? Then the second
33
+ assertion cannot be made effectively.
34
+
35
+ So this is why you're getting this exception. What can you do about it? As the
36
+ error message explains, you have two options:
37
+
38
+ 1. If you want the uniqueness validation in the model to operate
39
+ case-sensitively and you didn't mean to use a non-case-swappable value,
40
+ then you need to provide an existing record with a different value, one that
41
+ contains alpha characters. Here's an example:
42
+
43
+ # Model
44
+ class User < ActiveRecord::Base
45
+ validates_uniqueness_of :username
46
+ end
47
+
48
+ # RSpec
49
+ RSpec.describe User, type: :model do
50
+ context "validations" do
51
+ subject do
52
+ # Note that "123" == "123".swapcase. This is a problem!
53
+ User.new(username: "123")
54
+ end
55
+
56
+ it do
57
+ # So you can either override it like this, or just fix the subject.
58
+ user = User.create!(username: "john123")
59
+ expect(user).to validate_uniqueness_of(:username)
60
+ end
61
+ end
62
+ end
63
+
64
+ # Minitest (Shoulda)
65
+ class UserTest < ActiveSupport::TestCase
66
+ context "validations" do
67
+ subject do
68
+ # Note that "123" == "123".swapcase. This is a problem!
69
+ User.new(username: "123")
70
+ end
71
+
72
+ should "validate uniqueness of :username" do
73
+ # So you can either override it like this, or just fix the subject.
74
+ user = User.create!(username: "john123")
75
+ assert_accepts validate_uniqueness_of(:username), record
76
+ end
77
+ end
78
+ end
79
+
80
+ 2. If you don't want the uniqueness validation to operate case-sensitively,
81
+ then you need to add `case_sensitive: false` to the validation and add
82
+ `case_insensitive` to the matcher:
83
+
84
+ # Model
85
+ class User < ActiveRecord::Base
86
+ validates_uniqueness_of :username, case_sensitive: false
87
+ end
88
+
89
+ # RSpec
90
+ RSpec.describe User, type: :model do
91
+ context "validations" do
92
+ subject do
93
+ # Note that "123" == "123".swapcase, but it's okay
94
+ User.new(username: "123")
95
+ end
96
+
97
+ it { should validate_uniqueness_of(:username).case_insensitive }
98
+ end
99
+ end
100
+
101
+ # Minitest (Shoulda)
102
+ class UserTest < ActiveSupport::TestCase
103
+ context "validations" do
104
+ subject do
105
+ # Note that "123" == "123".swapcase, but it's okay
106
+ User.new(username: "123")
107
+ end
108
+
109
+ should validate_uniqueness_of(:username).case_insensitive
110
+ end
111
+ end
@@ -0,0 +1,121 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module ActionController
4
+ # The `use_before_action` matcher is used to test that a before_action
5
+ # callback is defined within your controller.
6
+ #
7
+ # class UsersController < ApplicationController
8
+ # before_action :authenticate_user!
9
+ # end
10
+ #
11
+ # # RSpec
12
+ # RSpec.describe UsersController, type: :controller do
13
+ # it { should use_before_action(:authenticate_user!) }
14
+ # it { should_not use_before_action(:prevent_ssl) }
15
+ # end
16
+ #
17
+ # # Minitest (Shoulda)
18
+ # class UsersControllerTest < ActionController::TestCase
19
+ # should use_before_action(:authenticate_user!)
20
+ # should_not use_before_action(:prevent_ssl)
21
+ # end
22
+ #
23
+ # @return [CallbackMatcher]
24
+ #
25
+ def use_before_action(callback)
26
+ CallbackMatcher.new(callback, :before, :action)
27
+ end
28
+
29
+ # The `use_after_action` matcher is used to test that an after_action
30
+ # callback is defined within your controller.
31
+ #
32
+ # class IssuesController < ApplicationController
33
+ # after_action :log_activity
34
+ # end
35
+ #
36
+ # # RSpec
37
+ # RSpec.describe IssuesController, type: :controller do
38
+ # it { should use_after_action(:log_activity) }
39
+ # it { should_not use_after_action(:destroy_user) }
40
+ # end
41
+ #
42
+ # # Minitest (Shoulda)
43
+ # class IssuesControllerTest < ActionController::TestCase
44
+ # should use_after_action(:log_activity)
45
+ # should_not use_after_action(:destroy_user)
46
+ # end
47
+ #
48
+ # @return [CallbackMatcher]
49
+ #
50
+ def use_after_action(callback)
51
+ CallbackMatcher.new(callback, :after, :action)
52
+ end
53
+
54
+ # The `use_around_action` matcher is used to test that an around_action
55
+ # callback is defined within your controller.
56
+ #
57
+ # class ChangesController < ApplicationController
58
+ # around_action :wrap_in_transaction
59
+ # end
60
+ #
61
+ # # RSpec
62
+ # RSpec.describe ChangesController, type: :controller do
63
+ # it { should use_around_action(:wrap_in_transaction) }
64
+ # it { should_not use_around_action(:save_view_context) }
65
+ # end
66
+ #
67
+ # # Minitest (Shoulda)
68
+ # class ChangesControllerTest < ActionController::TestCase
69
+ # should use_around_action(:wrap_in_transaction)
70
+ # should_not use_around_action(:save_view_context)
71
+ # end
72
+ #
73
+ # @return [CallbackMatcher]
74
+ #
75
+ def use_around_action(callback)
76
+ CallbackMatcher.new(callback, :around, :action)
77
+ end
78
+
79
+ # @private
80
+ class CallbackMatcher
81
+ def initialize(method_name, kind, callback_type)
82
+ @method_name = method_name
83
+ @kind = kind
84
+ @callback_type = callback_type
85
+ end
86
+
87
+ def matches?(controller)
88
+ @controller = controller
89
+ @controller_class = controller.class
90
+
91
+ callbacks.map(&:filter).include?(method_name)
92
+ end
93
+
94
+ def failure_message
95
+ "Expected that #{controller_class.name} would have :#{method_name}"\
96
+ " as a #{kind}_#{callback_type}"
97
+ end
98
+
99
+ def failure_message_when_negated
100
+ "Expected that #{controller_class.name} would not have"\
101
+ " :#{method_name} as a #{kind}_#{callback_type}"
102
+ end
103
+
104
+ def description
105
+ "have :#{method_name} as a #{kind}_#{callback_type}"
106
+ end
107
+
108
+ protected
109
+
110
+ def callbacks
111
+ controller_class._process_action_callbacks.select do |callback|
112
+ callback.kind == kind
113
+ end
114
+ end
115
+
116
+ attr_reader :method_name, :controller, :controller_class, :kind,
117
+ :callback_type
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,70 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module ActionController
4
+ # The `filter_param` matcher is used to test parameter filtering
5
+ # configuration. Specifically, it asserts that the given parameter is
6
+ # present in `config.filter_parameters`.
7
+ #
8
+ # class MyApplication < Rails::Application
9
+ # config.filter_parameters << :secret_key
10
+ # end
11
+ #
12
+ # # RSpec
13
+ # RSpec.describe ApplicationController, type: :controller do
14
+ # it { should filter_param(:secret_key) }
15
+ # end
16
+ #
17
+ # # Minitest (Shoulda)
18
+ # class ApplicationControllerTest < ActionController::TestCase
19
+ # should filter_param(:secret_key)
20
+ # end
21
+ #
22
+ # @return [FilterParamMatcher]
23
+ #
24
+ def filter_param(key)
25
+ FilterParamMatcher.new(key)
26
+ end
27
+
28
+ # @private
29
+ class FilterParamMatcher
30
+ def initialize(key)
31
+ @key = key
32
+ end
33
+
34
+ def matches?(_controller)
35
+ filters_key?
36
+ end
37
+
38
+ def failure_message
39
+ "Expected #{@key} to be filtered; filtered keys:"\
40
+ " #{filtered_keys.join(', ')}"
41
+ end
42
+
43
+ def failure_message_when_negated
44
+ "Did not expect #{@key} to be filtered"
45
+ end
46
+
47
+ def description
48
+ "filter #{@key}"
49
+ end
50
+
51
+ private
52
+
53
+ def filters_key?
54
+ filtered_keys.any? do |filter|
55
+ case filter
56
+ when Regexp
57
+ filter =~ @key
58
+ else
59
+ filter == @key
60
+ end
61
+ end
62
+ end
63
+
64
+ def filtered_keys
65
+ Rails.application.config.filter_parameters
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,86 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ module Shoulda
3
+ module Matchers
4
+ module ActionController
5
+ # @private
6
+ class FlashStore
7
+ def self.future
8
+ new
9
+ end
10
+
11
+ def self.now
12
+ new.use_now!
13
+ end
14
+
15
+ attr_accessor :controller
16
+
17
+ def initialize
18
+ @use_now = false
19
+ end
20
+
21
+ def name
22
+ if @use_now
23
+ 'flash.now'
24
+ else
25
+ 'flash'
26
+ end
27
+ end
28
+
29
+ def has_key?(key)
30
+ values_to_check.include?(key.to_s)
31
+ end
32
+
33
+ def has_value?(expected_value)
34
+ values_to_check.values.any? do |actual_value|
35
+ expected_value === actual_value
36
+ end
37
+ end
38
+ delegate :empty?, to: :flash
39
+
40
+ def use_now!
41
+ @use_now = true
42
+ self
43
+ end
44
+
45
+ private
46
+
47
+ def flash
48
+ @_flash ||= copy_of_flash_from_controller
49
+ end
50
+
51
+ def copy_of_flash_from_controller
52
+ controller.flash.dup.tap do |flash|
53
+ copy_flashes(controller.flash, flash)
54
+ copy_discard_if_necessary(controller.flash, flash)
55
+ end
56
+ end
57
+
58
+ def copy_flashes(original_flash, new_flash)
59
+ flashes = original_flash.instance_variable_get('@flashes').dup
60
+ new_flash.instance_variable_set('@flashes', flashes)
61
+ end
62
+
63
+ def copy_discard_if_necessary(original_flash, new_flash)
64
+ discard = original_flash.instance_variable_get('@discard').dup
65
+ new_flash.instance_variable_set('@discard', discard)
66
+ end
67
+
68
+ def set_values
69
+ flash.instance_variable_get('@flashes')
70
+ end
71
+
72
+ def keys_to_discard
73
+ flash.instance_variable_get('@discard')
74
+ end
75
+
76
+ def values_to_check
77
+ if @use_now
78
+ set_values.slice(*keys_to_discard.to_a)
79
+ else
80
+ set_values.except(*keys_to_discard.to_a)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end