actionpack 5.0.0.1 → 5.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +195 -0
  3. data/README.rdoc +1 -1
  4. data/lib/abstract_controller/callbacks.rb +3 -1
  5. data/lib/action_controller/metal/data_streaming.rb +1 -0
  6. data/lib/action_controller/metal/etag_with_template_digest.rb +7 -1
  7. data/lib/action_controller/metal/force_ssl.rb +1 -1
  8. data/lib/action_controller/metal/implicit_render.rb +1 -1
  9. data/lib/action_controller/metal/live.rb +6 -1
  10. data/lib/action_controller/metal/renderers.rb +0 -2
  11. data/lib/action_controller/metal/rendering.rb +1 -1
  12. data/lib/action_controller/metal/request_forgery_protection.rb +3 -3
  13. data/lib/action_controller/metal/strong_parameters.rb +53 -15
  14. data/lib/action_controller/test_case.rb +39 -21
  15. data/lib/action_dispatch.rb +1 -0
  16. data/lib/action_dispatch/http/headers.rb +1 -1
  17. data/lib/action_dispatch/http/mime_negotiation.rb +2 -2
  18. data/lib/action_dispatch/http/parameters.rb +8 -1
  19. data/lib/action_dispatch/http/request.rb +0 -12
  20. data/lib/action_dispatch/http/response.rb +15 -8
  21. data/lib/action_dispatch/journey/formatter.rb +3 -1
  22. data/lib/action_dispatch/journey/parser.rb +2 -0
  23. data/lib/action_dispatch/journey/parser_extras.rb +4 -2
  24. data/lib/action_dispatch/journey/route.rb +5 -3
  25. data/lib/action_dispatch/journey/router.rb +3 -1
  26. data/lib/action_dispatch/journey/visitors.rb +3 -1
  27. data/lib/action_dispatch/middleware/cookies.rb +3 -3
  28. data/lib/action_dispatch/middleware/debug_exceptions.rb +5 -1
  29. data/lib/action_dispatch/middleware/debug_locks.rb +122 -0
  30. data/lib/action_dispatch/middleware/exception_wrapper.rb +2 -2
  31. data/lib/action_dispatch/middleware/ssl.rb +14 -5
  32. data/lib/action_dispatch/middleware/static.rb +3 -3
  33. data/lib/action_dispatch/routing/mapper.rb +74 -61
  34. data/lib/action_dispatch/routing/redirection.rb +0 -1
  35. data/lib/action_dispatch/testing/integration.rb +150 -196
  36. data/lib/action_dispatch/testing/request_encoder.rb +53 -0
  37. data/lib/action_dispatch/testing/test_process.rb +2 -1
  38. data/lib/action_dispatch/testing/test_request.rb +1 -1
  39. data/lib/action_dispatch/testing/test_response.rb +7 -2
  40. data/lib/action_pack/gem_version.rb +2 -2
  41. metadata +13 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bb0ad18a371762c930292314cbc735989ac58fe
4
- data.tar.gz: b4e4ebf26e291aa7c6bf415d7efd5929d932991a
3
+ metadata.gz: ec4e939e3051bb6e62c29b8e14be2cf7fd3c1067
4
+ data.tar.gz: 52f14ea10ddf0ee7e4536f52ee615e08377ac783
5
5
  SHA512:
6
- metadata.gz: 167ba1621b9f649d8d2631648fc105efc8b7f46754b1847db1f6e5f0a01a4cdcfa40514d963853c3ed9ae436a79f0377645c185f03e9bf6ef0c3393cb75853b7
7
- data.tar.gz: 2822106415e6b68e4166905a8fcf99adbd6f07aa18463aa0e0b662c7066f21effb3d1de49fabbfd5a29a5fb0ab9dfa5b08aef4cbf9ec84925915a0fc2ccb64c6
6
+ metadata.gz: 558700b79b1d18c569d846bb1e44a3384c3e1c7f5dd6e4322f4d8a428b1d91e02cb5cc44b4e68facf0e6531f66dd05fcee2be7844c2f2320c5ac6b9763542a26
7
+ data.tar.gz: 7a8eee67d4a321617be9c909be937b7f0f0603404c731946d07b33a343bafc1e00656caef764c73b3ad6314625f44373a4db90d2255f6067906cd0def1476bd3
@@ -1,3 +1,198 @@
1
+ ## Rails 5.0.1.rc1 (December 01, 2016) ##
2
+
3
+ * Fixed error caused by `force_ssl_redirect` when `session_store` is
4
+ enabled.
5
+
6
+ Fixes #19679
7
+
8
+ *Taishi Kasuga*
9
+
10
+ * Use accept header in integration tests with `as: :json`
11
+
12
+ Instead of appending the `format` to the request path. Rails will figure
13
+ out the format from the header instead.
14
+
15
+ This allows devs to use `:as` on routes that don't have a format.
16
+
17
+ Fixes #27144.
18
+
19
+ *Kasper Timm Hansen*
20
+
21
+ * Fixed integration test requests appending and changing request paths.
22
+
23
+ #Before
24
+ post "/anything", params: params, headers: headers, as: :json
25
+
26
+ "/anything" would be converted to "/anything.json" based on format.
27
+ The path is now maintained and the format is respected based on `:as`
28
+ option.
29
+
30
+ Fixes #27144.
31
+
32
+ * Fixes incorrect output from rails routes when using singular resources.
33
+
34
+ Fixes #26606.
35
+
36
+ *Erick Reyna*
37
+
38
+ * Fixes multiple calls to `logger.fatal` instead of a single call,
39
+ for every line in an exception backtrace, when printing trace
40
+ from `DebugExceptions` middleware.
41
+
42
+ Fixes #26134.
43
+
44
+ *Vipul A M*
45
+
46
+ * Add `ActionController::Parameters#merge!`, which behaves the same as `Hash#merge!`.
47
+
48
+ *Yuji Yaginuma*
49
+
50
+ * Added `ActionController::Parameters#deep_dup` which actually creates
51
+ a params copy, instead of refereing to old references in params.
52
+
53
+ Fixes #26566.
54
+
55
+ *Pavel Evstigneev*, *Rafael Mendonça França*
56
+
57
+ * Make `fixture_file_upload` work in integration tests.
58
+
59
+ *Yuji Yaginuma*
60
+
61
+ * Add `to_param` to `ActionController::Parameters` deprecations.
62
+
63
+ In the future `ActionController::Parameters` are discouraged from being used
64
+ in URLs without explicit whitelisting. Go through `to_h` to use `to_param`.
65
+
66
+ *Kir Shatrov*
67
+
68
+ * Fix nested multiple roots
69
+
70
+ The PR #20940 enabled the use of multiple roots with different constraints
71
+ at the top level but unfortunately didn't work when those roots were inside
72
+ a namespace and also broke the use of root inside a namespace after a top
73
+ level root was defined because the check for the existence of the named route
74
+ used the global :root name and not the namespaced name.
75
+
76
+ This is fixed by using the name_for_action method to expand the :root name to
77
+ the full namespaced name. We can pass nil for the second argument as we're not
78
+ dealing with resource definitions so don't need to handle the cases for edit
79
+ and new routes.
80
+
81
+ Fixes #26148.
82
+
83
+ *Ryo Hashimoto*, *Andrew White*
84
+
85
+ * SSL: Changes redirect behavior for all non-GET and non-HEAD requests
86
+ (like POST/PUT/PATCH etc) to `http://` resources to redirect to `https://`
87
+ with a [307 status code](http://tools.ietf.org/html/rfc7231#section-6.4.7) instead of [301 status code](http://tools.ietf.org/html/rfc7231#section-6.4.2).
88
+
89
+ 307 status code instructs the HTTP clients to preserve the original
90
+ request method while redirecting. It has been part of HTTP RFC since
91
+ 1999 and is implemented/recognized by most (if not all) user agents.
92
+
93
+ # Before
94
+ POST http://example.com/articles (i.e. ArticlesContoller#create)
95
+ redirects to
96
+ GET https://example.com/articles (i.e. ArticlesContoller#index)
97
+
98
+ # After
99
+ POST http://example.com/articles (i.e. ArticlesContoller#create)
100
+ redirects to
101
+ POST https://example.com/articles (i.e. ArticlesContoller#create)
102
+
103
+ *Chirag Singhal*
104
+
105
+ * Add `:as` option to `ActionController:TestCase#process` and related methods.
106
+
107
+ Specifying `as: mime_type` allows the `CONTENT_TYPE` header to be specified
108
+ in controller tests without manually doing this through `@request.headers['CONTENT_TYPE']`.
109
+
110
+ *Everest Stefan Munro-Zeisberger*
111
+
112
+ * Prevent autoload from deadlocking while ActionController::Live is streaming.
113
+
114
+ *Alex Chinn*
115
+
116
+ * Don't override the `Accept` header in integration tests when called with `xhr: true`.
117
+
118
+ Fixes #25859.
119
+
120
+ *David Chen*
121
+
122
+ * Fix 'defaults' option for root route.
123
+
124
+ A regression from some refactoring for the 5.0 release, this change
125
+ fixes the use of 'defaults' (default parameters) in the 'root' routing method.
126
+
127
+ *Chris Arcand*
128
+
129
+ * Check `request.path_parameters` encoding at the point they're set.
130
+
131
+ Check for any non-UTF8 characters in path parameters at the point they're
132
+ set in `env`. Previously they were checked for when used to get a controller
133
+ class, but this meant routes that went directly to a Rack app, or skipped
134
+ controller instantiation for some other reason, had to defend against
135
+ non-UTF8 characters themselves.
136
+
137
+ *Grey Baker*
138
+
139
+ * Don't raise ActionController::UnknownHttpMethod from ActionDispatch::Static
140
+
141
+ Pass `Rack::Request` objects to `ActionDispatch::FileHandler` to avoid it
142
+ raising `ActionController::UnknownHttpMethod`. If an unknown method is
143
+ passed, it should exception higher in the stack instead, once we've had a
144
+ chance to define exception handling behaviour.
145
+
146
+ *Grey Baker*
147
+
148
+ * Handle `Rack::QueryParser` errors in `ActionDispatch::ExceptionWrapper`
149
+
150
+ Updated `ActionDispatch::ExceptionWrapper` to handle the Rack 2.0 namespace
151
+ for `ParameterTypeError` and `InvalidParameterError` errors.
152
+
153
+ *Grey Baker*
154
+
155
+ * Deprecated omitting the route path.
156
+ Specify the path with a String or a Symbol instead.
157
+
158
+ # Before
159
+ get action: :show, as: :show
160
+ # After
161
+ get "", action: :show, as: :show
162
+
163
+ *Volmer*
164
+
165
+ * Added new `ActionDispatch::DebugLocks` middleware that can be used
166
+ to diagnose deadlocks in the autoload interlock.
167
+ To use it, insert it near the top of the middleware stack, using
168
+ `config/application.rb`:
169
+
170
+ config.middleware.insert_before Rack::Sendfile, ActionDispatch::DebugLocks
171
+
172
+ After adding, visiting `/rails/locks` will show a summary of all
173
+ threads currently known to the interlock.
174
+
175
+ *Matthew Draper*
176
+
177
+ * Fix request encoding in Integration tests when string literals are
178
+ frozen using `--enable-frozen-string-literal` or `# frozen_string_literal: true`.
179
+
180
+ *Volmer*
181
+
182
+ * Since long keys are truncated when passed to ciphers, Ruby 2.4
183
+ doesn't accept keys greater than their max length.
184
+ Fixed default key length on cipher for `ActiveSupport::MessageEncryptor`,
185
+ which was causing errors on Ruby 2.4.
186
+
187
+ *Vipul A M*
188
+
189
+ * Fixed adding implicitly rendered template digests to ETags.
190
+ Properly ignore implicit template cache option to ETag, if `template: false`
191
+ is passed when rendering.
192
+
193
+ *Javan Makhmali*
194
+
195
+
1
196
  ## Rails 5.0.0 (June 30, 2016) ##
2
197
 
3
198
  * Add `ActionController#helpers` to get access to the view context at the controller
@@ -32,7 +32,7 @@ The latest version of Action Pack can be installed with RubyGems:
32
32
 
33
33
  Source code can be downloaded as part of the Rails project on GitHub
34
34
 
35
- * https://github.com/rails/rails/tree/master/actionpack
35
+ * https://github.com/rails/rails/tree/5-0-stable/actionpack
36
36
 
37
37
 
38
38
  == License
@@ -70,7 +70,9 @@ module AbstractController
70
70
 
71
71
  def skip_filter(*names)
72
72
  ActiveSupport::Deprecation.warn("`skip_filter` is deprecated and will be removed in Rails 5.1. Use skip_before_action, skip_after_action or skip_around_action instead.")
73
- skip_action_callback(*names)
73
+ skip_before_action(*names, raise: false)
74
+ skip_after_action(*names, raise: false)
75
+ skip_around_action(*names, raise: false)
74
76
  end
75
77
 
76
78
  # Take callback names and an optional callback proc, normalize them,
@@ -70,6 +70,7 @@ module ActionController #:nodoc:
70
70
  send_file_headers! options
71
71
 
72
72
  self.status = options[:status] || 200
73
+ self.content_type = options[:type] if options.key?(:type)
73
74
  self.content_type = options[:content_type] if options.key?(:content_type)
74
75
  response.send_file path
75
76
  end
@@ -39,8 +39,14 @@ module ActionController
39
39
  end
40
40
  end
41
41
 
42
+ # Pick the template digest to include in the ETag. If the +:template+ option
43
+ # is present, use the named template. If +:template+ is nil or absent, use
44
+ # the default controller/action template. If +:template+ is false, omit the
45
+ # template digest from the ETag.
42
46
  def pick_template_for_etag(options)
43
- options.fetch(:template) { "#{controller_name}/#{action_name}" }
47
+ unless options[:template] == false
48
+ options[:template] || "#{controller_path}/#{action_name}"
49
+ end
44
50
  end
45
51
 
46
52
  def lookup_and_digest_template(template)
@@ -89,7 +89,7 @@ module ActionController
89
89
  end
90
90
 
91
91
  secure_url = ActionDispatch::Http::URL.url_for(options.slice(*URL_OPTIONS))
92
- flash.keep if respond_to?(:flash)
92
+ flash.keep if respond_to?(:flash) && request.respond_to?(:flash)
93
93
  redirect_to secure_url, options.slice(*REDIRECT_OPTIONS)
94
94
  end
95
95
  end
@@ -49,7 +49,7 @@ module ActionController
49
49
  "NOTE! For XHR/Ajax or API requests, this action would normally " \
50
50
  "respond with 204 No Content: an empty white screen. Since you're " \
51
51
  "loading it in a web browser, we assume that you expected to " \
52
- "actually render a template, not nothing, so we're showing an " \
52
+ "actually render a template, not nothing, so we're showing an " \
53
53
  "error to be extra-clear. If you expect 204 No Content, carry on. " \
54
54
  "That's what you'll get from an XHR or API request. Give it a shot."
55
55
 
@@ -206,7 +206,12 @@ module ActionController
206
206
  private
207
207
 
208
208
  def each_chunk(&block)
209
- while str = @buf.pop
209
+ loop do
210
+ str = nil
211
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
212
+ str = @buf.pop
213
+ end
214
+ break unless str
210
215
  yield str
211
216
  end
212
217
  end
@@ -71,8 +71,6 @@ module ActionController
71
71
  # format.csv { render csv: @csvable, filename: @csvable.name }
72
72
  # end
73
73
  # end
74
- # To use renderers and their mime types in more concise ways, see
75
- # <tt>ActionController::MimeResponds::ClassMethods.respond_to</tt>
76
74
  def self.add(key, &block)
77
75
  define_method(_render_with_renderer_method_name(key), &block)
78
76
  RENDERERS << key.to_sym
@@ -90,7 +90,7 @@ module ActionController
90
90
  render as `text/plain`, `render html: '<strong>HTML</strong>'` to
91
91
  render as `text/html`, or `render body: 'raw'` to match the deprecated
92
92
  behavior and render with the default Content-Type, which is
93
- `text/plain`.
93
+ `text/html`.
94
94
  WARNING
95
95
  end
96
96
 
@@ -109,10 +109,10 @@ module ActionController #:nodoc:
109
109
  # * <tt>:only/:except</tt> - Only apply forgery protection to a subset of actions. For example <tt>only: [ :create, :create_all ]</tt>.
110
110
  # * <tt>:if/:unless</tt> - Turn off the forgery protection entirely depending on the passed Proc or method reference.
111
111
  # * <tt>:prepend</tt> - By default, the verification of the authentication token will be added at the position of the
112
- # protect_from_forgery call in your application. This means any callbacks added before are run first. This is useful
113
- # when you want your forgery protection to depend on other callbacks, like authentication methods (Oauth vs Cookie auth).
112
+ # protect_from_forgery call in your application. This means any callbacks added before are run first. This is useful
113
+ # when you want your forgery protection to depend on other callbacks, like authentication methods (Oauth vs Cookie auth).
114
114
  #
115
- # If you need to add verification to the beginning of the callback chain, use <tt>prepend: true</tt>.
115
+ # If you need to add verification to the beginning of the callback chain, use <tt>prepend: true</tt>.
116
116
  # * <tt>:with</tt> - Set the method to handle unverified request.
117
117
  #
118
118
  # Valid unverified request handling methods are:
@@ -2,11 +2,13 @@ require 'active_support/core_ext/hash/indifferent_access'
2
2
  require 'active_support/core_ext/hash/transform_values'
3
3
  require 'active_support/core_ext/array/wrap'
4
4
  require 'active_support/core_ext/string/filters'
5
+ require 'active_support/core_ext/object/to_query'
5
6
  require 'active_support/rescuable'
6
7
  require 'action_dispatch/http/upload'
7
8
  require 'rack/test'
8
9
  require 'stringio'
9
10
  require 'set'
11
+ require 'yaml'
10
12
 
11
13
  module ActionController
12
14
  # Raised when a required parameter is missing.
@@ -571,28 +573,21 @@ module ActionController
571
573
  convert_value_to_parameters(@parameters.values_at(*keys))
572
574
  end
573
575
 
574
- # Returns an exact copy of the <tt>ActionController::Parameters</tt>
575
- # instance. +permitted+ state is kept on the duped object.
576
- #
577
- # params = ActionController::Parameters.new(a: 1)
578
- # params.permit!
579
- # params.permitted? # => true
580
- # copy_params = params.dup # => {"a"=>1}
581
- # copy_params.permitted? # => true
582
- def dup
583
- super.tap do |duplicate|
584
- duplicate.permitted = @permitted
585
- end
586
- end
587
-
588
576
  # Returns a new <tt>ActionController::Parameters</tt> with all keys from
589
577
  # +other_hash+ merges into current hash.
590
578
  def merge(other_hash)
591
579
  new_instance_with_inherited_permitted_status(
592
- @parameters.merge(other_hash)
580
+ @parameters.merge(other_hash.to_h)
593
581
  )
594
582
  end
595
583
 
584
+ # Returns current <tt>ActionController::Parameters</tt> instance which
585
+ # +other_hash+ merges into current hash.
586
+ def merge!(other_hash)
587
+ @parameters.merge!(other_hash.to_h)
588
+ self
589
+ end
590
+
596
591
  # This is required by ActiveModel attribute assignment, so that user can
597
592
  # pass +Parameters+ to a mass assignment methods in a model. It should not
598
593
  # matter as we are using +HashWithIndifferentAccess+ internally.
@@ -604,6 +599,37 @@ module ActionController
604
599
  "<#{self.class} #{@parameters} permitted: #{@permitted}>"
605
600
  end
606
601
 
602
+ def self.hook_into_yaml_loading # :nodoc:
603
+ # Wire up YAML format compatibility with Rails 4.2 and Psych 2.0.8 and 2.0.9+.
604
+ # Makes the YAML parser call `init_with` when it encounters the keys below
605
+ # instead of trying its own parsing routines.
606
+ YAML.load_tags['!ruby/hash-with-ivars:ActionController::Parameters'] = name
607
+ YAML.load_tags['!ruby/hash:ActionController::Parameters'] = name
608
+ end
609
+ hook_into_yaml_loading
610
+
611
+ def init_with(coder) # :nodoc:
612
+ case coder.tag
613
+ when '!ruby/hash:ActionController::Parameters'
614
+ # YAML 2.0.8's format where hash instance variables weren't stored.
615
+ @parameters = coder.map.with_indifferent_access
616
+ @permitted = false
617
+ when '!ruby/hash-with-ivars:ActionController::Parameters'
618
+ # YAML 2.0.9's Hash subclass format where keys and values
619
+ # were stored under an elements hash and `permitted` within an ivars hash.
620
+ @parameters = coder.map['elements'].with_indifferent_access
621
+ @permitted = coder.map['ivars'][:@permitted]
622
+ when '!ruby/object:ActionController::Parameters'
623
+ # YAML's Object format. Only needed because of the format
624
+ # backwardscompability above, otherwise equivalent to YAML's initialization.
625
+ @parameters, @permitted = coder.map['parameters'], coder.map['permitted']
626
+ end
627
+ end
628
+
629
+ # Undefine `to_param` such that it gets caught in the `method_missing`
630
+ # deprecation cycle below.
631
+ undef_method :to_param
632
+
607
633
  def method_missing(method_sym, *args, &block)
608
634
  if @parameters.respond_to?(method_sym)
609
635
  message = <<-DEPRECATE.squish
@@ -622,6 +648,13 @@ module ActionController
622
648
  end
623
649
  end
624
650
 
651
+ # Returns duplicate of object including all parameters
652
+ def deep_dup
653
+ self.class.new(@parameters.deep_dup).tap do |duplicate|
654
+ duplicate.permitted = @permitted
655
+ end
656
+ end
657
+
625
658
  protected
626
659
  attr_reader :parameters
627
660
 
@@ -782,6 +815,11 @@ module ActionController
782
815
  end
783
816
  end
784
817
  end
818
+
819
+ def initialize_copy(source)
820
+ super
821
+ @parameters = @parameters.dup
822
+ end
785
823
  end
786
824
 
787
825
  # == Strong \Parameters
@@ -7,7 +7,6 @@ require 'action_controller/template_assertions'
7
7
  require 'rails-dom-testing'
8
8
 
9
9
  module ActionController
10
- # :stopdoc:
11
10
  class Metal
12
11
  include Testing::Functional
13
12
  end
@@ -50,7 +49,7 @@ module ActionController
50
49
  super(env)
51
50
 
52
51
  self.session = session
53
- self.session_options = TestSession::DEFAULT_OPTIONS
52
+ self.session_options = TestSession::DEFAULT_OPTIONS.dup
54
53
  @custom_param_parsers = {
55
54
  xml: lambda { |raw_post| Hash.from_xml(raw_post)['hash'] }
56
55
  }
@@ -110,8 +109,9 @@ module ActionController
110
109
  end
111
110
  end
112
111
 
113
- set_header 'CONTENT_LENGTH', data.length.to_s
114
- set_header 'rack.input', StringIO.new(data)
112
+ data_stream = StringIO.new(data)
113
+ set_header "CONTENT_LENGTH", data_stream.length.to_s
114
+ set_header "rack.input", data_stream
115
115
  end
116
116
 
117
117
  fetch_header("PATH_INFO") do |k|
@@ -208,10 +208,18 @@ module ActionController
208
208
  end
209
209
 
210
210
  # Superclass for ActionController functional tests. Functional tests allow you to
211
- # test a single controller action per test method. This should not be confused with
212
- # integration tests (see ActionDispatch::IntegrationTest), which are more like
213
- # "stories" that can involve multiple controllers and multiple actions (i.e. multiple
214
- # different HTTP requests).
211
+ # test a single controller action per test method.
212
+ #
213
+ # == Use integration style controller tests over functional style controller tests.
214
+ #
215
+ # Rails discourages the use of functional tests in favor of integration tests
216
+ # (use ActionDispatch::IntegrationTest).
217
+ #
218
+ # New Rails applications no longer generate functional style controller tests and they should
219
+ # only be used for backward compatibility. Integration style controller tests perform actual
220
+ # requests, whereas functional style controller tests merely simulate a request. Besides,
221
+ # integration tests are as fast as functional tests and provide lot of helpers such as +as+,
222
+ # +parsed_body+ for effective testing of controller actions including even API endpoints.
215
223
  #
216
224
  # == Basic example
217
225
  #
@@ -415,8 +423,8 @@ module ActionController
415
423
 
416
424
  def xml_http_request(*args)
417
425
  ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc)
418
- xhr and xml_http_request methods are deprecated in favor of
419
- `get :index, xhr: true` and `post :create, xhr: true`
426
+ `xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1.
427
+ Switch to e.g. `post :create, params: { comment: { body: 'Honey bunny' } }, xhr: true`.
420
428
  MSG
421
429
 
422
430
  @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
@@ -440,6 +448,8 @@ module ActionController
440
448
  # - +session+: A hash of parameters to store in the session. This may be +nil+.
441
449
  # - +flash+: A hash of parameters to store in the flash. This may be +nil+.
442
450
  # - +format+: Request format. Defaults to +nil+. Can be string or symbol.
451
+ # - +as+: Content type. Defaults to +nil+. Must be a symbol that corresponds
452
+ # to a mime type.
443
453
  #
444
454
  # Example calling +create+ action and sending two params:
445
455
  #
@@ -460,7 +470,7 @@ module ActionController
460
470
  check_required_ivars
461
471
 
462
472
  if kwarg_request?(args)
463
- parameters, session, body, flash, http_method, format, xhr = args[0].values_at(:params, :session, :body, :flash, :method, :format, :xhr)
473
+ parameters, session, body, flash, http_method, format, xhr, as = args[0].values_at(:params, :session, :body, :flash, :method, :format, :xhr, :as)
464
474
  else
465
475
  http_method, parameters, session, flash = args
466
476
  format = nil
@@ -487,10 +497,6 @@ module ActionController
487
497
 
488
498
  parameters ||= {}
489
499
 
490
- if format
491
- parameters[:format] = format
492
- end
493
-
494
500
  @html_document = nil
495
501
 
496
502
  self.cookies.update @request.cookies
@@ -505,6 +511,15 @@ module ActionController
505
511
 
506
512
  @request.set_header 'REQUEST_METHOD', http_method
507
513
 
514
+ if as
515
+ @request.content_type = Mime[as].to_s
516
+ format ||= as
517
+ end
518
+
519
+ if format
520
+ parameters[:format] = format
521
+ end
522
+
508
523
  parameters = parameters.symbolize_keys
509
524
 
510
525
  generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s))
@@ -611,6 +626,7 @@ module ActionController
611
626
  include ActionDispatch::Assertions
612
627
  class_attribute :_controller_class
613
628
  setup :setup_controller_request_and_response
629
+ ActiveSupport.run_load_hooks(:action_controller_test_case, self)
614
630
  end
615
631
 
616
632
  private
@@ -620,6 +636,7 @@ module ActionController
620
636
  env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
621
637
  env.delete 'action_dispatch.request.query_parameters'
622
638
  env.delete 'action_dispatch.request.request_parameters'
639
+ env['rack.input'] = StringIO.new
623
640
  env
624
641
  end
625
642
 
@@ -645,13 +662,15 @@ module ActionController
645
662
 
646
663
  def non_kwarg_request_warning
647
664
  ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc)
648
- ActionController::TestCase HTTP request methods will accept only
649
- keyword arguments in future Rails versions.
665
+ Using positional arguments in functional tests has been deprecated,
666
+ in favor of keyword arguments, and will be removed in Rails 5.1.
650
667
 
651
- Examples:
668
+ Deprecated style:
669
+ get :show, { id: 1 }, nil, { notice: "This is a flash message" }
652
670
 
653
- get :show, params: { id: 1 }, session: { user_id: 1 }
654
- process :update, method: :post, params: { id: 1 }
671
+ New keyword style:
672
+ get :show, params: { id: 1 }, flash: { notice: "This is a flash message" },
673
+ session: nil # Can safely be omitted.
655
674
  MSG
656
675
  end
657
676
 
@@ -677,5 +696,4 @@ module ActionController
677
696
 
678
697
  include Behavior
679
698
  end
680
- # :startdoc:
681
699
  end