actionpack 5.0.0.beta1.1 → 5.0.0.beta2

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -28
  3. data/MIT-LICENSE +1 -1
  4. data/lib/abstract_controller/base.rb +2 -2
  5. data/lib/abstract_controller/rendering.rb +5 -5
  6. data/lib/action_controller.rb +4 -0
  7. data/lib/action_controller/api.rb +1 -1
  8. data/lib/action_controller/api/api_rendering.rb +14 -0
  9. data/lib/action_controller/metal.rb +2 -1
  10. data/lib/action_controller/metal/conditional_get.rb +1 -1
  11. data/lib/action_controller/metal/head.rb +0 -1
  12. data/lib/action_controller/metal/mime_responds.rb +9 -4
  13. data/lib/action_controller/metal/renderers.rb +75 -32
  14. data/lib/action_controller/metal/request_forgery_protection.rb +54 -11
  15. data/lib/action_controller/metal/strong_parameters.rb +33 -10
  16. data/lib/action_controller/test_case.rb +8 -8
  17. data/lib/action_dispatch.rb +2 -1
  18. data/lib/action_dispatch/http/cache.rb +10 -2
  19. data/lib/action_dispatch/http/headers.rb +15 -1
  20. data/lib/action_dispatch/http/mime_negotiation.rb +3 -3
  21. data/lib/action_dispatch/http/mime_type.rb +38 -47
  22. data/lib/action_dispatch/http/parameters.rb +1 -1
  23. data/lib/action_dispatch/http/request.rb +1 -1
  24. data/lib/action_dispatch/http/response.rb +8 -1
  25. data/lib/action_dispatch/journey/path/pattern.rb +1 -1
  26. data/lib/action_dispatch/middleware/ssl.rb +23 -17
  27. data/lib/action_dispatch/middleware/stack.rb +9 -0
  28. data/lib/action_dispatch/middleware/static.rb +5 -1
  29. data/lib/action_dispatch/request/session.rb +3 -3
  30. data/lib/action_dispatch/routing.rb +2 -1
  31. data/lib/action_dispatch/routing/inspector.rb +22 -10
  32. data/lib/action_dispatch/routing/mapper.rb +41 -35
  33. data/lib/action_dispatch/routing/route_set.rb +11 -2
  34. data/lib/action_dispatch/testing/assertion_response.rb +49 -0
  35. data/lib/action_dispatch/testing/assertions/response.rb +14 -14
  36. data/lib/action_dispatch/testing/test_process.rb +0 -1
  37. data/lib/action_pack.rb +1 -1
  38. data/lib/action_pack/gem_version.rb +1 -1
  39. metadata +12 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c08a2a9ff55bdc33124d0f4381c07760230e956
4
- data.tar.gz: 553434784aa0485a9da3040c51620d132e9f6cd9
3
+ metadata.gz: 9b471942b30689112172143f0c7f110a47bb07c1
4
+ data.tar.gz: 96f4cb5ab8175de829b41313fca5068e8d37e081
5
5
  SHA512:
6
- metadata.gz: 92aa1f71eb971a0a949a6192c634f2bbab1ee06a8a103ac12b723d3875bdb57c461529dad3121b449944d55dc3f03cb4ceed23e6512cbbed833e42c2a98357a4
7
- data.tar.gz: 0ca4502fde02f1cd4f31402fc760250e1a3583790def111feab5dce600e68a6486dd39cdfe0adf40ed07b1a704f24b8fbd05f2ef9147a0485c9ab10df8bf7849
6
+ metadata.gz: dd1182095560e1b846a1fa4d793481ace31c98481efc8027f37815a0c1d98196e04b77466849bdcb13563e7c9345739461088cbb0d365dcfa945034619001f88
7
+ data.tar.gz: 1932992f247727b865f236e20d8a286d1aeb8641c10e351386e976dad9f8a69f9cfb869d27b73cded695632de855be978c75de88be55a9abd8cbe36b8c87ee97
@@ -1,7 +1,64 @@
1
- ## Rails 5.0.0.beta1 (December 18, 2015) ##
1
+ ## Rails 5.0.0.beta2 (February 01, 2016) ##
2
+
3
+ * Add `-g` and `-c` (short for _grep_ and _controller_ respectively) options
4
+ to `bin/rake routes`. These options return the url `name`, `verb` and
5
+ `path` field that match the pattern or match a specific controller.
6
+
7
+ Deprecate `CONTROLLER` env variable in `bin/rake routes`.
8
+
9
+ See #18902.
10
+
11
+ *Anton Davydov* & *Vipul A M*
12
+
13
+ * Response etags to always be weak: Prefixes 'W/' to value returned by
14
+ `ActionDispatch::Http::Cache::Response#etag=`, such that etags set in
15
+ `fresh_when` and `stale?` are weak.
16
+
17
+ Fixes #17556.
18
+
19
+ *Abhishek Yadav*
20
+
21
+ * Provide the name of HTTP Status code in assertions.
22
+
23
+ *Sean Collins*
24
+
25
+ * More explicit error message when running `rake routes`. `CONTROLLER` argument
26
+ can now be supplied in different ways:
27
+ `Rails::WelcomeController`, `Rails::Welcome`, `rails/welcome`.
28
+
29
+ Fixes #22918.
30
+
31
+ *Edouard Chin*
32
+
33
+ * Allow `ActionController::Parameters` instances as an argument to URL
34
+ helper methods. An `ArgumentError` will be raised if the passed parameters
35
+ are not secure.
36
+
37
+ Fixes #22832.
38
+
39
+ *Prathamesh Sonpatki*
2
40
 
3
- * No changes.
41
+ * Add option for per-form CSRF tokens.
4
42
 
43
+ *Greg Ose & Ben Toews*
44
+
45
+ * Add tests and documentation for `ActionController::Renderers::use_renderers`.
46
+
47
+ *Benjamin Fleischer*
48
+
49
+ * Fix `ActionController::Parameters#convert_parameters_to_hashes` to return filtered
50
+ or unfiltered values based on from where it is called, `to_h` or `to_unsafe_h`
51
+ respectively.
52
+
53
+ Fixes #22841.
54
+
55
+ *Prathamesh Sonpatki*
56
+
57
+ * Add `ActionController::Parameters#include?`
58
+
59
+ *Justin Coyne*
60
+
61
+ ## Rails 5.0.0.beta1 (December 18, 2015) ##
5
62
 
6
63
  * Deprecate `redirect_to :back` in favor of `redirect_back`, which accepts a
7
64
  required `fallback_location` argument, thus eliminating the possibility of a
@@ -37,13 +94,13 @@
37
94
 
38
95
  *Jorge Bejar*
39
96
 
40
- * Change the `protect_from_forgery` prepend default to `false`
97
+ * Change the `protect_from_forgery` prepend default to `false`.
41
98
 
42
99
  Per this comment
43
100
  https://github.com/rails/rails/pull/18334#issuecomment-69234050 we want
44
101
  `protect_from_forgery` to default to `prepend: false`.
45
102
 
46
- `protect_from_forgery` will now be insterted into the callback chain at the
103
+ `protect_from_forgery` will now be inserted into the callback chain at the
47
104
  point it is called in your application. This is useful for cases where you
48
105
  want to `protect_from_forgery` after you perform required authentication
49
106
  callbacks or other callbacks that are required to run after forgery protection.
@@ -85,26 +142,29 @@
85
142
 
86
143
  *Agis Anastasopoulos*
87
144
 
88
- * Add the ability of returning arbitrary headers to ActionDispatch::Static
145
+ * Add the ability of returning arbitrary headers to `ActionDispatch::Static`.
89
146
 
90
147
  Now ActionDispatch::Static can accept HTTP headers so that developers
91
148
  will have control of returning arbitrary headers like
92
149
  'Access-Control-Allow-Origin' when a response is delivered. They can be
93
150
  configured with `#config`:
94
151
 
95
- config.public_file_server.headers = {
96
- "Cache-Control" => "public, max-age=60",
97
- "Access-Control-Allow-Origin" => "http://rubyonrails.org"
98
- }
152
+ Example:
153
+
154
+ config.public_file_server.headers = {
155
+ "Cache-Control" => "public, max-age=60",
156
+ "Access-Control-Allow-Origin" => "http://rubyonrails.org"
157
+ }
99
158
 
100
159
  *Yuki Nishijima*
101
160
 
102
161
  * Allow multiple `root` routes in same scope level. Example:
103
162
 
104
- ```ruby
105
- root 'blog#show', constraints: ->(req) { Hostname.blog_site?(req.host) }
106
- root 'landing#show'
107
- ```
163
+ Example:
164
+
165
+ root 'blog#show', constraints: ->(req) { Hostname.blog_site?(req.host) }
166
+ root 'landing#show'
167
+
108
168
  *Rafael Sales*
109
169
 
110
170
  * Fix regression in mounted engine named routes generation for app deployed to
@@ -115,12 +175,12 @@
115
175
 
116
176
  *Matthew Erhard*
117
177
 
118
- * ActionDispatch::Response#new no longer applies default headers. If you want
178
+ * `ActionDispatch::Response#new` no longer applies default headers. If you want
119
179
  default headers applied to the response object, then call
120
- `ActionDispatch::Response.create`. This change only impacts people who are
180
+ `ActionDispatch::Response.create`. This change only impacts people who are
121
181
  directly constructing an `ActionDispatch::Response` object.
122
182
 
123
- * Accessing mime types via constants like `Mime::HTML` is deprecated. Please
183
+ * Accessing mime types via constants like `Mime::HTML` is deprecated. Please
124
184
  change code like this:
125
185
 
126
186
  Mime::HTML
@@ -173,7 +233,7 @@
173
233
 
174
234
  *Jeremy Friesen*
175
235
 
176
- * Using strings or symbols for middleware class names is deprecated. Convert
236
+ * Using strings or symbols for middleware class names is deprecated. Convert
177
237
  things like this:
178
238
 
179
239
  middleware.use "Foo::Bar"
@@ -182,10 +242,10 @@
182
242
 
183
243
  middleware.use Foo::Bar
184
244
 
185
- * ActionController::TestSession now accepts a default value as well as
245
+ * `ActionController::TestSession` now accepts a default value as well as
186
246
  a block for generating a default value based off the key provided.
187
247
 
188
- This fixes calls to session#fetch in ApplicationController instances that
248
+ This fixes calls to `session#fetch` in `ApplicationController` instances that
189
249
  take more two arguments or a block from raising `ArgumentError: wrong
190
250
  number of arguments (2 for 1)` when performing controller tests.
191
251
 
@@ -236,10 +296,10 @@
236
296
  *Grey Baker*
237
297
 
238
298
  * Add support for API only apps.
239
- ActionController::API is added as a replacement of
240
- ActionController::Base for this kind of applications.
299
+ `ActionController::API` is added as a replacement of
300
+ `ActionController::Base` for this kind of applications.
241
301
 
242
- *Santiago Pastorino & Jorge Bejar*
302
+ *Santiago Pastorino*, *Jorge Bejar*
243
303
 
244
304
  * Remove `assigns` and `assert_template`. Both methods have been extracted
245
305
  into a gem at https://github.com/rails/rails-controller-testing.
@@ -314,7 +374,7 @@
314
374
 
315
375
  * Allow `Bearer` as token-keyword in `Authorization-Header`.
316
376
 
317
- Aditionally to `Token`, the keyword `Bearer` is acceptable as a keyword
377
+ Additionally to `Token`, the keyword `Bearer` is acceptable as a keyword
318
378
  for the auth-token. The `Bearer` keyword is described in the original
319
379
  OAuth RFC and used in libraries like Angular-JWT.
320
380
 
@@ -322,7 +382,7 @@
322
382
 
323
383
  *Peter Schröder*
324
384
 
325
- * Drop request class from RouteSet constructor.
385
+ * Drop request class from `RouteSet` constructor.
326
386
 
327
387
  If you would like to use a custom request class, please subclass and implement
328
388
  the `request_class` method.
@@ -351,7 +411,7 @@
351
411
 
352
412
  *Jeremy Kemper*, *Yves Senn*
353
413
 
354
- * Deprecate AbstractController#skip_action_callback in favor of individual skip_callback methods
414
+ * Deprecate `AbstractController#skip_action_callback` in favor of individual skip_callback methods
355
415
  (which can be made to raise an error if no callback was removed).
356
416
 
357
417
  *Iain Beeston*
@@ -557,9 +617,7 @@
557
617
  Fixes an issue where when an exception is raised in the request the additional
558
618
  payload data is not available.
559
619
 
560
- See:
561
- * #14903
562
- * https://github.com/roidrage/lograge/issues/37
620
+ See #14903.
563
621
 
564
622
  *Dieter Komendera*, *Margus Pärt*
565
623
 
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2015 David Heinemeier Hansson
1
+ Copyright (c) 2004-2016 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -49,7 +49,7 @@ module AbstractController
49
49
  # instance methods on that abstract class. Public instance methods of
50
50
  # a controller would normally be considered action methods, so methods
51
51
  # declared on abstract classes are being removed.
52
- # (ActionController::Metal and ActionController::Base are defined as abstract)
52
+ # (<tt>ActionController::Metal</tt> and ActionController::Base are defined as abstract)
53
53
  def internal_methods
54
54
  controller = self
55
55
 
@@ -80,7 +80,7 @@ module AbstractController
80
80
 
81
81
  # action_methods are cached and there is sometimes need to refresh
82
82
  # them. ::clear_action_methods! allows you to do that, so next time
83
- # you run action_methods, they will be recalculated
83
+ # you run action_methods, they will be recalculated.
84
84
  def clear_action_methods!
85
85
  @action_methods = nil
86
86
  end
@@ -82,13 +82,13 @@ module AbstractController
82
82
  # <tt>render :file => "foo/bar"</tt>.
83
83
  # :api: plugin
84
84
  def _normalize_args(action=nil, options={})
85
- case action
86
- when ActionController::Parameters
87
- unless action.permitted?
85
+ if action.respond_to?(:permitted?)
86
+ if action.permitted?
87
+ action
88
+ else
88
89
  raise ArgumentError, "render parameters are not permitted"
89
90
  end
90
- action
91
- when Hash
91
+ elsif action.is_a?(Hash)
92
92
  action
93
93
  else
94
94
  options
@@ -41,6 +41,10 @@ module ActionController
41
41
  autoload :UrlFor
42
42
  end
43
43
 
44
+ autoload_under "api" do
45
+ autoload :ApiRendering
46
+ end
47
+
44
48
  autoload :TestCase, 'action_controller/test_case'
45
49
  autoload :TemplateAssertions, 'action_controller/test_case'
46
50
 
@@ -112,7 +112,7 @@ module ActionController
112
112
 
113
113
  UrlFor,
114
114
  Redirecting,
115
- Rendering,
115
+ ApiRendering,
116
116
  Renderers::All,
117
117
  ConditionalGet,
118
118
  BasicImplicitRender,
@@ -0,0 +1,14 @@
1
+ module ActionController
2
+ module ApiRendering
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Rendering
7
+ end
8
+
9
+ def render_to_body(options = {})
10
+ _process_options(options)
11
+ super
12
+ end
13
+ end
14
+ end
@@ -166,7 +166,7 @@ module ActionController
166
166
 
167
167
  alias :response_code :status # :nodoc:
168
168
 
169
- # Basic url_for that can be overridden for more robust functionality
169
+ # Basic url_for that can be overridden for more robust functionality.
170
170
  def url_for(string)
171
171
  string
172
172
  end
@@ -174,6 +174,7 @@ module ActionController
174
174
  def response_body=(body)
175
175
  body = [body] unless body.nil? || body.respond_to?(:each)
176
176
  response.reset_body!
177
+ return unless body
177
178
  body.each { |part|
178
179
  next if part.empty?
179
180
  response.write part
@@ -228,7 +228,7 @@ module ActionController
228
228
  expires_in 100.years, public: public
229
229
 
230
230
  yield if stale?(etag: "#{version}-#{request.fullpath}",
231
- last_modified: Time.parse('2011-01-01').utc,
231
+ last_modified: Time.new(2011, 1, 1).utc,
232
232
  public: public)
233
233
  end
234
234
 
@@ -50,7 +50,6 @@ module ActionController
50
50
  end
51
51
 
52
52
  private
53
- # :nodoc:
54
53
  def include_content?(status)
55
54
  case status
56
55
  when 100..199
@@ -9,6 +9,13 @@ module ActionController #:nodoc:
9
9
  # @people = Person.all
10
10
  # end
11
11
  #
12
+ # That action implicitly responds to all formats, but formats can also be whitelisted:
13
+ #
14
+ # def index
15
+ # @people = Person.all
16
+ # respond_to :html, :js
17
+ # end
18
+ #
12
19
  # Here's the same action, with web-service support baked in:
13
20
  #
14
21
  # def index
@@ -16,11 +23,12 @@ module ActionController #:nodoc:
16
23
  #
17
24
  # respond_to do |format|
18
25
  # format.html
26
+ # format.js
19
27
  # format.xml { render xml: @people }
20
28
  # end
21
29
  # end
22
30
  #
23
- # What that says is, "if the client wants HTML in response to this action, just respond as we
31
+ # What that says is, "if the client wants HTML or JS in response to this action, just respond as we
24
32
  # would have before, but if the client wants XML, return them the list of people in XML format."
25
33
  # (Rails determines the desired response format from the HTTP Accept header submitted by the client.)
26
34
  #
@@ -180,9 +188,6 @@ module ActionController #:nodoc:
180
188
  # format.html.none
181
189
  # format.html.phone # this gets rendered
182
190
  # end
183
- #
184
- # Be sure to check the documentation of <tt>ActionController::MimeResponds.respond_to</tt>
185
- # for more examples.
186
191
  def respond_to(*mimes)
187
192
  raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given?
188
193
 
@@ -11,6 +11,7 @@ module ActionController
11
11
  Renderers.remove(key)
12
12
  end
13
13
 
14
+ # See <tt>Responder#api_behavior</tt>
14
15
  class MissingRenderer < LoadError
15
16
  def initialize(format)
16
17
  super "No renderer defined for format: #{format}"
@@ -20,40 +21,25 @@ module ActionController
20
21
  module Renderers
21
22
  extend ActiveSupport::Concern
22
23
 
24
+ # A Set containing renderer names that correspond to available renderer procs.
25
+ # Default values are <tt>:json</tt>, <tt>:js</tt>, <tt>:xml</tt>.
26
+ RENDERERS = Set.new
27
+
23
28
  included do
24
29
  class_attribute :_renderers
25
30
  self._renderers = Set.new.freeze
26
31
  end
27
32
 
28
- module ClassMethods
29
- def use_renderers(*args)
30
- renderers = _renderers + args
31
- self._renderers = renderers.freeze
32
- end
33
- alias use_renderer use_renderers
34
- end
35
-
36
- def render_to_body(options)
37
- _render_to_body_with_renderer(options) || super
38
- end
33
+ # Used in <tt>ActionController::Base</tt>
34
+ # and <tt>ActionController::API</tt> to include all
35
+ # renderers by default.
36
+ module All
37
+ extend ActiveSupport::Concern
38
+ include Renderers
39
39
 
40
- def _render_to_body_with_renderer(options)
41
- _renderers.each do |name|
42
- if options.key?(name)
43
- _process_options(options)
44
- method_name = Renderers._render_with_renderer_method_name(name)
45
- return send(method_name, options.delete(name), options)
46
- end
40
+ included do
41
+ self._renderers = RENDERERS
47
42
  end
48
- nil
49
- end
50
-
51
- # A Set containing renderer names that correspond to available renderer procs.
52
- # Default values are <tt>:json</tt>, <tt>:js</tt>, <tt>:xml</tt>.
53
- RENDERERS = Set.new
54
-
55
- def self._render_with_renderer_method_name(key)
56
- "_render_with_renderer_#{key}"
57
43
  end
58
44
 
59
45
  # Adds a new renderer to call within controller actions.
@@ -103,13 +89,70 @@ module ActionController
103
89
  remove_method(method_name) if method_defined?(method_name)
104
90
  end
105
91
 
106
- module All
107
- extend ActiveSupport::Concern
108
- include Renderers
92
+ def self._render_with_renderer_method_name(key)
93
+ "_render_with_renderer_#{key}"
94
+ end
109
95
 
110
- included do
111
- self._renderers = RENDERERS
96
+ module ClassMethods
97
+
98
+ # Adds, by name, a renderer or renderers to the +_renderers+ available
99
+ # to call within controller actions.
100
+ #
101
+ # It is useful when rendering from an <tt>ActionController::Metal</tt> controller or
102
+ # otherwise to add an available renderer proc to a specific controller.
103
+ #
104
+ # Both <tt>ActionController::Base</tt> and <tt>ActionController::API</tt>
105
+ # include <tt>ActionController::Renderers::All</tt>, making all renderers
106
+ # avaialable in the controller. See <tt>Renderers::RENDERERS</tt> and <tt>Renderers.add</tt>.
107
+ #
108
+ # Since <tt>ActionController::Metal</tt> controllers cannot render, the controller
109
+ # must include <tt>AbstractController::Rendering</tt>, <tt>ActionController::Rendering</tt>,
110
+ # and <tt>ActionController::Renderers</tt>, and have at lest one renderer.
111
+ #
112
+ # Rather than including <tt>ActionController::Renderers::All</tt> and including all renderers,
113
+ # you may specify which renderers to include by passing the renderer name or names to
114
+ # +use_renderers+. For example, a controller that includes only the <tt>:json</tt> renderer
115
+ # (+_render_with_renderer_json+) might look like:
116
+ #
117
+ # class MetalRenderingController < ActionController::Metal
118
+ # include AbstractController::Rendering
119
+ # include ActionController::Rendering
120
+ # include ActionController::Renderers
121
+ #
122
+ # use_renderers :json
123
+ #
124
+ # def show
125
+ # render json: record
126
+ # end
127
+ # end
128
+ #
129
+ # You must specify a +use_renderer+, else the +controller.renderer+ and
130
+ # +controller._renderers+ will be <tt>nil</tt>, and the action will fail.
131
+ def use_renderers(*args)
132
+ renderers = _renderers + args
133
+ self._renderers = renderers.freeze
112
134
  end
135
+ alias use_renderer use_renderers
136
+ end
137
+
138
+ # Called by +render+ in <tt>AbstractController::Rendering</tt>
139
+ # which sets the return value as the +response_body+.
140
+ #
141
+ # If no renderer is found, +super+ returns control to
142
+ # <tt>ActionView::Rendering.render_to_body</tt>, if present.
143
+ def render_to_body(options)
144
+ _render_to_body_with_renderer(options) || super
145
+ end
146
+
147
+ def _render_to_body_with_renderer(options)
148
+ _renderers.each do |name|
149
+ if options.key?(name)
150
+ _process_options(options)
151
+ method_name = Renderers._render_with_renderer_method_name(name)
152
+ return send(method_name, options.delete(name), options)
153
+ end
154
+ end
155
+ nil
113
156
  end
114
157
 
115
158
  add :json do |json, options|