shoulda-matchers 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +8 -0
  5. data/Appraisals +82 -33
  6. data/Gemfile +18 -2
  7. data/Gemfile.lock +13 -1
  8. data/NEWS.md +27 -2
  9. data/README.md +83 -1329
  10. data/Rakefile +118 -1
  11. data/cucumber.yml +1 -0
  12. data/doc_config/gh-pages/index.html.erb +9 -0
  13. data/doc_config/yard/setup.rb +22 -0
  14. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +5967 -0
  15. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +12 -0
  16. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +45 -0
  17. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +69 -0
  18. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +283 -0
  19. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +32 -0
  20. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +1 -0
  21. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +8 -0
  22. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +298 -0
  23. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +1 -0
  24. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +289 -0
  25. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +6 -0
  26. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +8 -0
  27. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +14 -0
  28. data/doc_config/yard/templates/default/layout/html/fonts.erb +1 -0
  29. data/doc_config/yard/templates/default/layout/html/layout.erb +23 -0
  30. data/doc_config/yard/templates/default/layout/html/search.erb +13 -0
  31. data/doc_config/yard/templates/default/layout/html/setup.rb +40 -0
  32. data/doc_config/yard/templates/default/method_details/html/source.erb +10 -0
  33. data/doc_config/yard/templates/default/module/html/box_info.erb +31 -0
  34. data/docs.watchr +5 -0
  35. data/features/rails_integration.feature +32 -0
  36. data/features/step_definitions/rails_steps.rb +55 -9
  37. data/features/support/env.rb +1 -0
  38. data/gemfiles/3.0.gemfile +13 -1
  39. data/gemfiles/3.0.gemfile.lock +13 -1
  40. data/gemfiles/3.1.gemfile +17 -2
  41. data/gemfiles/3.1.gemfile.lock +31 -2
  42. data/gemfiles/3.1_1.9.2.gemfile +33 -0
  43. data/gemfiles/3.1_1.9.2.gemfile.lock +203 -0
  44. data/gemfiles/3.2.gemfile +18 -2
  45. data/gemfiles/3.2.gemfile.lock +32 -2
  46. data/gemfiles/3.2_1.9.2.gemfile +32 -0
  47. data/gemfiles/3.2_1.9.2.gemfile.lock +200 -0
  48. data/gemfiles/4.0.0.gemfile +20 -1
  49. data/gemfiles/4.0.0.gemfile.lock +46 -2
  50. data/gemfiles/4.0.1.gemfile +20 -1
  51. data/gemfiles/4.0.1.gemfile.lock +46 -2
  52. data/gemfiles/4.1.gemfile +21 -2
  53. data/gemfiles/4.1.gemfile.lock +47 -4
  54. data/lib/shoulda/matchers/action_controller.rb +0 -20
  55. data/lib/shoulda/matchers/action_controller/callback_matcher.rb +119 -28
  56. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +22 -6
  57. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +43 -10
  58. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +40 -13
  59. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +63 -11
  60. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +34 -1
  61. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +84 -15
  62. data/lib/shoulda/matchers/action_controller/route_matcher.rb +84 -28
  63. data/lib/shoulda/matchers/action_controller/route_params.rb +4 -3
  64. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +76 -13
  65. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +147 -13
  66. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +148 -2
  67. data/lib/shoulda/matchers/active_model.rb +0 -25
  68. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +66 -9
  69. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +161 -19
  70. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +5 -5
  71. data/lib/shoulda/matchers/active_model/ensure_exclusion_of_matcher.rb +92 -13
  72. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +218 -16
  73. data/lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb +198 -32
  74. data/lib/shoulda/matchers/active_model/errors.rb +5 -2
  75. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +1 -1
  76. data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +29 -8
  77. data/lib/shoulda/matchers/active_model/helpers.rb +20 -8
  78. data/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
  79. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +4 -6
  80. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +4 -3
  81. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +3 -2
  82. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +4 -3
  83. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +4 -3
  84. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +52 -14
  85. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +51 -13
  86. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +53 -7
  87. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +275 -19
  88. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +84 -14
  89. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +170 -41
  90. data/lib/shoulda/matchers/active_model/validation_matcher.rb +20 -15
  91. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -2
  92. data/lib/shoulda/matchers/active_record.rb +1 -12
  93. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +89 -15
  94. data/lib/shoulda/matchers/active_record/association_matcher.rb +726 -70
  95. data/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
  96. data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +4 -3
  97. data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -3
  98. data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +4 -3
  99. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +2 -1
  100. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +4 -3
  101. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +4 -5
  102. data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +4 -3
  103. data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +4 -3
  104. data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +4 -3
  105. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +79 -15
  106. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +64 -15
  107. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +21 -7
  108. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +85 -10
  109. data/lib/shoulda/matchers/assertion_error.rb +7 -1
  110. data/lib/shoulda/matchers/doublespeak.rb +2 -1
  111. data/lib/shoulda/matchers/doublespeak/double.rb +3 -1
  112. data/lib/shoulda/matchers/doublespeak/double_collection.rb +2 -1
  113. data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +1 -0
  114. data/lib/shoulda/matchers/doublespeak/object_double.rb +2 -1
  115. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +2 -1
  116. data/lib/shoulda/matchers/doublespeak/structs.rb +2 -0
  117. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +2 -1
  118. data/lib/shoulda/matchers/doublespeak/world.rb +3 -4
  119. data/lib/shoulda/matchers/error.rb +1 -0
  120. data/lib/shoulda/matchers/independent/delegate_matcher.rb +108 -20
  121. data/lib/shoulda/matchers/independent/delegate_matcher/stubbed_target.rb +4 -3
  122. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +3 -0
  123. data/lib/shoulda/matchers/rails_shim.rb +3 -2
  124. data/lib/shoulda/matchers/version.rb +2 -1
  125. data/lib/shoulda/matchers/warn.rb +1 -0
  126. data/script/SUPPORTED_VERSIONS +1 -0
  127. data/script/install_gems_in_all_appraisals +14 -0
  128. data/script/run_all_tests +14 -0
  129. data/shoulda-matchers.gemspec +0 -10
  130. data/spec/report_warnings.rb +7 -0
  131. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +1 -1
  132. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +9 -0
  133. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -36
  134. data/spec/shoulda/matchers/active_model/validation_message_finder_spec.rb +2 -2
  135. data/spec/shoulda/matchers/doublespeak/double_spec.rb +1 -1
  136. data/spec/shoulda/matchers/doublespeak/world_spec.rb +11 -29
  137. data/spec/shoulda/matchers/doublespeak_spec.rb +3 -3
  138. data/spec/spec_helper.rb +17 -0
  139. data/spec/support/class_builder.rb +4 -0
  140. data/spec/support/test_application.rb +1 -1
  141. data/spec/warnings_spy.rb +64 -0
  142. data/spec/warnings_spy/filesystem.rb +45 -0
  143. data/spec/warnings_spy/partitioner.rb +29 -0
  144. data/spec/warnings_spy/reader.rb +64 -0
  145. data/spec/warnings_spy/reporter.rb +87 -0
  146. metadata +49 -134
@@ -1,6 +1,7 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
3
+ module ActionController
4
+ # @private
4
5
  class RouteParams
5
6
  def initialize(args)
6
7
  @args = args
@@ -14,7 +15,7 @@ module Shoulda # :nodoc:
14
15
  end
15
16
  end
16
17
 
17
- private
18
+ protected
18
19
 
19
20
  attr_reader :args
20
21
 
@@ -1,21 +1,79 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
-
5
- # Ensures that a session key was set to the expected value.
3
+ module ActionController
4
+ # The `set_session` matcher is used to make assertions about the
5
+ # `session` hash.
6
+ #
7
+ # class PostsController < ApplicationController
8
+ # def show
9
+ # session[:foo] = 'bar'
10
+ # end
11
+ # end
12
+ #
13
+ # # RSpec
14
+ # describe PostsController do
15
+ # describe 'GET #show' do
16
+ # before { get :show }
17
+ #
18
+ # it { should set_session(:foo) }
19
+ # it { should_not set_session(:baz) }
20
+ # end
21
+ # end
22
+ #
23
+ # # Test::Unit
24
+ # class PostsControllerTest < ActionController::TestCase
25
+ # context 'GET #show' do
26
+ # setup { get :show }
27
+ #
28
+ # should set_session(:foo)
29
+ # should_not set_session(:baz)
30
+ # end
31
+ # end
32
+ #
33
+ # #### Qualifiers
34
+ #
35
+ # ##### to
36
+ #
37
+ # Use `to` to assert that the key in the session hash was set to a
38
+ # particular value.
6
39
  #
7
- # Example:
40
+ # class PostsController < ApplicationController
41
+ # def show
42
+ # session[:foo] = 'bar'
43
+ # end
44
+ # end
45
+ #
46
+ # # RSpec
47
+ # describe PostsController do
48
+ # describe 'GET #show' do
49
+ # before { get :show }
50
+ #
51
+ # it { should set_session(:foo).to('bar') }
52
+ # it { should_not set_session(:foo).to('something else') }
53
+ # end
54
+ # end
55
+ #
56
+ # # Test::Unit
57
+ # class PostsControllerTest < ActionController::TestCase
58
+ # context 'GET #show' do
59
+ # setup { get :show }
60
+ #
61
+ # should set_session(:foo).to('bar')
62
+ # should_not set_session(:foo).to('something else')
63
+ # end
64
+ # end
65
+ #
66
+ # @return [SetSessionMatcher]
8
67
  #
9
- # it { should set_session(:message) }
10
- # it { should set_session(:user_id).to(@user.id) }
11
- # it { should_not set_session(:user_id) }
12
68
  def set_session(key)
13
69
  SetSessionMatcher.new(key)
14
70
  end
15
71
 
16
- class SetSessionMatcher # :nodoc:
72
+ # @private
73
+ class SetSessionMatcher
17
74
  def initialize(key)
18
75
  @key = key.to_s
76
+ @value_block = nil
19
77
  end
20
78
 
21
79
  def to(value = nil, &block)
@@ -57,6 +115,10 @@ module Shoulda # :nodoc:
57
115
 
58
116
  private
59
117
 
118
+ def value_or_default_value
119
+ defined?(@value) && @value
120
+ end
121
+
60
122
  def assigned_value?
61
123
  !assigned_value.nil?
62
124
  end
@@ -67,10 +129,10 @@ module Shoulda # :nodoc:
67
129
 
68
130
  def assigned_correct_value?
69
131
  if assigned_value?
70
- if @value.nil?
132
+ if value_or_default_value.nil?
71
133
  true
72
134
  else
73
- assigned_value == @value
135
+ assigned_value == value_or_default_value
74
136
  end
75
137
  end
76
138
  end
@@ -81,8 +143,9 @@ module Shoulda # :nodoc:
81
143
 
82
144
  def expectation
83
145
  expectation = "session variable #{@key} to be set"
84
- if @value
85
- expectation << " to #{@value.inspect}"
146
+
147
+ if value_or_default_value
148
+ expectation << " to #{value_or_default_value.inspect}"
86
149
  end
87
150
  end
88
151
 
@@ -1,25 +1,159 @@
1
- module Shoulda # :nodoc:
1
+ module Shoulda
2
2
  module Matchers
3
- module ActionController # :nodoc:
4
-
5
- # Ensures that the flash contains the given value. Can be a String, a
6
- # Regexp, or nil (indicating that the flash should not be set).
3
+ module ActionController
4
+ # The `set_the_flash` matcher is used to make assertions about the
5
+ # `flash` hash.
6
+ #
7
+ # class PostsController < ApplicationController
8
+ # def index
9
+ # flash[:foo] = 'A candy bar'
10
+ # end
11
+ #
12
+ # def destroy
13
+ # end
14
+ # end
15
+ #
16
+ # # RSpec
17
+ # describe PostsController do
18
+ # describe 'GET #index' do
19
+ # before { get :index }
20
+ #
21
+ # it { should set_the_flash }
22
+ # end
23
+ #
24
+ # describe 'DELETE #destroy' do
25
+ # before { delete :destroy }
26
+ #
27
+ # it { should_not set_the_flash }
28
+ # end
29
+ # end
30
+ #
31
+ # # Test::Unit
32
+ # class PostsControllerTest < ActionController::TestCase
33
+ # context 'GET #index' do
34
+ # setup { get :index }
35
+ #
36
+ # should set_the_flash
37
+ # end
38
+ #
39
+ # context 'DELETE #destroy' do
40
+ # setup { delete :destroy }
41
+ #
42
+ # should_not set_the_flash
43
+ # end
44
+ # end
45
+ #
46
+ # #### Qualifiers
47
+ #
48
+ # ##### []
49
+ #
50
+ # Use `[]` to narrow the scope of the matcher to a particular key.
51
+ #
52
+ # class PostsController < ApplicationController
53
+ # def index
54
+ # flash[:foo] = 'A candy bar'
55
+ # end
56
+ # end
57
+ #
58
+ # # RSpec
59
+ # describe PostsController do
60
+ # describe 'GET #index' do
61
+ # before { get :index }
62
+ #
63
+ # it { should set_the_flash[:foo] }
64
+ # it { should_not set_the_flash[:bar] }
65
+ # end
66
+ # end
67
+ #
68
+ # # Test::Unit
69
+ # class PostsControllerTest < ActionController::TestCase
70
+ # context 'GET #index' do
71
+ # setup { get :show }
72
+ #
73
+ # should set_the_flash[:foo]
74
+ # should_not set_the_flash[:bar]
75
+ # end
76
+ # end
77
+ #
78
+ # ##### to
79
+ #
80
+ # Use `to` to assert that some key was set to a particular value, or that
81
+ # some key matches a particular regex.
82
+ #
83
+ # class PostsController < ApplicationController
84
+ # def index
85
+ # flash[:foo] = 'A candy bar'
86
+ # end
87
+ # end
88
+ #
89
+ # # RSpec
90
+ # describe PostsController do
91
+ # describe 'GET #index' do
92
+ # before { get :index }
93
+ #
94
+ # it { should set_the_flash.to('A candy bar') }
95
+ # it { should set_the_flash.to(/bar/) }
96
+ # it { should set_the_flash[:foo].to('bar') }
97
+ # it { should_not set_the_flash[:foo].to('something else') }
98
+ # end
99
+ # end
100
+ #
101
+ # # Test::Unit
102
+ # class PostsControllerTest < ActionController::TestCase
103
+ # context 'GET #index' do
104
+ # setup { get :show }
105
+ #
106
+ # should set_the_flash.to('A candy bar')
107
+ # should set_the_flash.to(/bar/)
108
+ # should set_the_flash[:foo].to('bar')
109
+ # should_not set_the_flash[:foo].to('something else')
110
+ # end
111
+ # end
112
+ #
113
+ # ##### now
114
+ #
115
+ # Use `now` to change the scope of the matcher to use the "now" hash
116
+ # instead of the usual "future" hash.
117
+ #
118
+ # class PostsController < ApplicationController
119
+ # def show
120
+ # flash.now[:foo] = 'bar'
121
+ # end
122
+ # end
123
+ #
124
+ # # RSpec
125
+ # describe PostsController do
126
+ # describe 'GET #show' do
127
+ # before { get :show }
128
+ #
129
+ # it { should set_the_flash.now }
130
+ # it { should set_the_flash[:foo].now }
131
+ # it { should set_the_flash[:foo].to('bar').now }
132
+ # end
133
+ # end
134
+ #
135
+ # # Test::Unit
136
+ # class PostsControllerTest < ActionController::TestCase
137
+ # context 'GET #index' do
138
+ # setup { get :show }
139
+ #
140
+ # should set_the_flash.now
141
+ # should set_the_flash[:foo].now
142
+ # should set_the_flash[:foo].to('bar').now
143
+ # end
144
+ # end
7
145
  #
8
- # Example:
146
+ # @return [SetTheFlashMatcher]
9
147
  #
10
- # it { should set_the_flash }
11
- # it { should set_the_flash.to('Thank you for placing this order.') }
12
- # it { should set_the_flash.to(/created/i) }
13
- # it { should set_the_flash[:alert].to('Password does not match') }
14
- # it { should set_the_flash.to(/logged in/i).now }
15
- # it { should_not set_the_flash }
16
148
  def set_the_flash
17
149
  SetTheFlashMatcher.new
18
150
  end
19
151
 
20
- class SetTheFlashMatcher # :nodoc:
152
+ # @private
153
+ class SetTheFlashMatcher
21
154
  def initialize
22
155
  @options = {}
156
+ @value = nil
23
157
  end
24
158
 
25
159
  def to(value)
@@ -10,10 +10,154 @@ require 'active_support/hash_with_indifferent_access'
10
10
  module Shoulda
11
11
  module Matchers
12
12
  module ActionController
13
+ # The `permit` matcher tests that an action in your controller receives a
14
+ # whitelist of parameters using Rails' Strong Parameters feature
15
+ # (specifically that `permit` was called with the correct arguments).
16
+ #
17
+ # Here's an example:
18
+ #
19
+ # class UsersController < ApplicationController
20
+ # def create
21
+ # user = User.create(user_params)
22
+ # # ...
23
+ # end
24
+ #
25
+ # private
26
+ #
27
+ # def user_params
28
+ # params.require(:user).permit(
29
+ # :first_name,
30
+ # :last_name,
31
+ # :email,
32
+ # :password
33
+ # )
34
+ # end
35
+ # end
36
+ #
37
+ # # RSpec
38
+ # describe UsersController do
39
+ # it do
40
+ # should permit(:first_name, :last_name, :email, :password).
41
+ # for(:create)
42
+ # end
43
+ # end
44
+ #
45
+ # # Test::Unit
46
+ # class UsersControllerTest < ActionController::TestCase
47
+ # should permit(:first_name, :last_name, :email, :password).
48
+ # for(:create)
49
+ # end
50
+ #
51
+ # If your action requires query parameters in order to work, then you'll
52
+ # need to supply them:
53
+ #
54
+ # class UsersController < ApplicationController
55
+ # def update
56
+ # user = User.find(params[:id])
57
+ #
58
+ # if user.update_attributes(user_params)
59
+ # # ...
60
+ # else
61
+ # # ...
62
+ # end
63
+ # end
64
+ #
65
+ # private
66
+ #
67
+ # def user_params
68
+ # params.require(:user).permit(
69
+ # :first_name,
70
+ # :last_name,
71
+ # :email,
72
+ # :password
73
+ # )
74
+ # end
75
+ # end
76
+ #
77
+ # # RSpec
78
+ # describe UsersController do
79
+ # before do
80
+ # create(:user, id: 1)
81
+ # end
82
+ #
83
+ # it do
84
+ # should permit(:first_name, :last_name, :email, :password).
85
+ # for(:update, params: { id: 1 })
86
+ # end
87
+ # end
88
+ #
89
+ # # Test::Unit
90
+ # class UsersControllerTest < ActionController::TestCase
91
+ # setup do
92
+ # create(:user, id: 1)
93
+ # end
94
+ #
95
+ # should permit(:first_name, :last_name, :email, :password).
96
+ # for(:update, params: { id: 1 })
97
+ # end
98
+ #
99
+ # Finally, if you have an action that isn't one of the seven resourceful
100
+ # actions, then you'll need to provide the HTTP verb that it responds to:
101
+ #
102
+ # Rails.application.routes.draw do
103
+ # resources :users do
104
+ # member do
105
+ # put :toggle
106
+ # end
107
+ # end
108
+ # end
109
+ #
110
+ # class UsersController < ApplicationController
111
+ # def toggle
112
+ # user = User.find(params[:id])
113
+ #
114
+ # if user.update_attributes(user_params)
115
+ # # ...
116
+ # else
117
+ # # ...
118
+ # end
119
+ # end
120
+ #
121
+ # private
122
+ #
123
+ # def user_params
124
+ # params.require(:user).permit(:activated)
125
+ # end
126
+ # end
127
+ #
128
+ # # RSpec
129
+ # describe UsersController do
130
+ # before do
131
+ # create(:user, id: 1)
132
+ # end
133
+ #
134
+ # it do
135
+ # should permit(:activated).for(:toggle,
136
+ # params: { id: 1 },
137
+ # verb: :put
138
+ # )
139
+ # end
140
+ # end
141
+ #
142
+ # # Test::Unit
143
+ # class UsersControllerTest < ActionController::TestCase
144
+ # setup do
145
+ # create(:user, id: 1)
146
+ # end
147
+ #
148
+ # should permit(:activated).for(:toggle,
149
+ # params: { id: 1 },
150
+ # verb: :put
151
+ # )
152
+ # end
153
+ #
154
+ # @return [StrongParametersMatcher]
155
+ #
13
156
  def permit(*params)
14
157
  StrongParametersMatcher.new(params).in_context(self)
15
158
  end
16
159
 
160
+ # @private
17
161
  class StrongParametersMatcher
18
162
  attr_writer :stubbed_params
19
163
 
@@ -62,14 +206,14 @@ module Shoulda
62
206
  end
63
207
  alias failure_message_for_should_not failure_message_when_negated
64
208
 
65
- private
209
+ protected
66
210
 
67
211
  attr_reader :controller, :double_collection, :action, :verb,
68
212
  :request_params, :expected_permitted_params, :context
69
213
 
70
214
  def set_double_collection
71
215
  @double_collection =
72
- Doublespeak.register_double_collection(::ActionController::Parameters)
216
+ Doublespeak.double_collection_for(::ActionController::Parameters)
73
217
 
74
218
  @double_collection.register_stub(:require).to_return { |params| params }
75
219
  @double_collection.register_proxy(:permit)
@@ -114,12 +258,14 @@ module Shoulda
114
258
  expected_permitted_params.map(&:inspect).to_sentence
115
259
  end
116
260
 
261
+ # @private
117
262
  class ActionNotDefinedError < StandardError
118
263
  def message
119
264
  'You must specify the controller action using the #for method.'
120
265
  end
121
266
  end
122
267
 
268
+ # @private
123
269
  class VerbNotDefinedError < StandardError
124
270
  def message
125
271
  'You must specify an HTTP verb when using a non-RESTful action. For example: for(:authorize, verb: :post)'