actionpack 4.1.7 → 4.2.1

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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +311 -527
  3. data/README.rdoc +7 -2
  4. data/lib/abstract_controller/base.rb +16 -6
  5. data/lib/abstract_controller/callbacks.rb +28 -51
  6. data/lib/abstract_controller/helpers.rb +11 -4
  7. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  8. data/lib/abstract_controller/url_for.rb +1 -1
  9. data/lib/action_controller/base.rb +2 -1
  10. data/lib/action_controller/caching/fragments.rb +7 -1
  11. data/lib/action_controller/caching.rb +1 -1
  12. data/lib/action_controller/log_subscriber.rb +26 -26
  13. data/lib/action_controller/metal/conditional_get.rb +37 -12
  14. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  15. data/lib/action_controller/metal/exceptions.rb +1 -1
  16. data/lib/action_controller/metal/force_ssl.rb +1 -1
  17. data/lib/action_controller/metal/head.rb +7 -3
  18. data/lib/action_controller/metal/http_authentication.rb +14 -9
  19. data/lib/action_controller/metal/instrumentation.rb +8 -5
  20. data/lib/action_controller/metal/live.rb +57 -6
  21. data/lib/action_controller/metal/mime_responds.rb +23 -246
  22. data/lib/action_controller/metal/params_wrapper.rb +2 -2
  23. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  24. data/lib/action_controller/metal/redirecting.rb +14 -8
  25. data/lib/action_controller/metal/renderers.rb +30 -10
  26. data/lib/action_controller/metal/rendering.rb +2 -6
  27. data/lib/action_controller/metal/request_forgery_protection.rb +78 -7
  28. data/lib/action_controller/metal/streaming.rb +1 -1
  29. data/lib/action_controller/metal/strong_parameters.rb +125 -12
  30. data/lib/action_controller/metal/url_for.rb +11 -12
  31. data/lib/action_controller/metal.rb +12 -11
  32. data/lib/action_controller/model_naming.rb +1 -1
  33. data/lib/action_controller/railtie.rb +4 -0
  34. data/lib/action_controller/test_case.rb +112 -75
  35. data/lib/action_controller.rb +1 -1
  36. data/lib/action_dispatch/http/cache.rb +5 -4
  37. data/lib/action_dispatch/http/filter_parameters.rb +2 -2
  38. data/lib/action_dispatch/http/headers.rb +43 -9
  39. data/lib/action_dispatch/http/mime_negotiation.rb +10 -3
  40. data/lib/action_dispatch/http/mime_type.rb +2 -2
  41. data/lib/action_dispatch/http/parameter_filter.rb +1 -1
  42. data/lib/action_dispatch/http/parameters.rb +11 -26
  43. data/lib/action_dispatch/http/request.rb +37 -11
  44. data/lib/action_dispatch/http/response.rb +70 -18
  45. data/lib/action_dispatch/http/upload.rb +3 -8
  46. data/lib/action_dispatch/http/url.rb +88 -69
  47. data/lib/action_dispatch/journey/formatter.rb +33 -17
  48. data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
  49. data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
  50. data/lib/action_dispatch/journey/gtg/transition_table.rb +20 -28
  51. data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
  52. data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
  53. data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
  54. data/lib/action_dispatch/journey/nodes/node.rb +4 -0
  55. data/lib/action_dispatch/journey/parser.rb +52 -60
  56. data/lib/action_dispatch/journey/parser.y +11 -10
  57. data/lib/action_dispatch/journey/path/pattern.rb +16 -19
  58. data/lib/action_dispatch/journey/route.rb +3 -18
  59. data/lib/action_dispatch/journey/router/strexp.rb +9 -6
  60. data/lib/action_dispatch/journey/router.rb +53 -77
  61. data/lib/action_dispatch/journey/scanner.rb +5 -5
  62. data/lib/action_dispatch/journey/visitors.rb +81 -92
  63. data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
  64. data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
  65. data/lib/action_dispatch/middleware/callbacks.rb +1 -1
  66. data/lib/action_dispatch/middleware/cookies.rb +29 -29
  67. data/lib/action_dispatch/middleware/debug_exceptions.rb +15 -4
  68. data/lib/action_dispatch/middleware/exception_wrapper.rb +50 -18
  69. data/lib/action_dispatch/middleware/flash.rb +13 -7
  70. data/lib/action_dispatch/middleware/params_parser.rb +1 -1
  71. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
  72. data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
  73. data/lib/action_dispatch/middleware/request_id.rb +1 -1
  74. data/lib/action_dispatch/middleware/session/cookie_store.rb +1 -1
  75. data/lib/action_dispatch/middleware/show_exceptions.rb +1 -0
  76. data/lib/action_dispatch/middleware/static.rb +66 -37
  77. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
  78. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +37 -9
  79. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +2 -8
  80. data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +0 -0
  81. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  82. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
  83. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +4 -0
  84. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +2 -0
  85. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -24
  86. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +0 -1
  87. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
  88. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  89. data/lib/action_dispatch/routing/inspector.rb +5 -12
  90. data/lib/action_dispatch/routing/mapper.rb +410 -281
  91. data/lib/action_dispatch/routing/polymorphic_routes.rb +191 -79
  92. data/lib/action_dispatch/routing/redirection.rb +10 -12
  93. data/lib/action_dispatch/routing/route_set.rb +297 -168
  94. data/lib/action_dispatch/routing/url_for.rb +15 -4
  95. data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
  96. data/lib/action_dispatch/testing/assertions/response.rb +2 -7
  97. data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
  98. data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
  99. data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
  100. data/lib/action_dispatch/testing/assertions.rb +11 -7
  101. data/lib/action_dispatch/testing/integration.rb +24 -19
  102. data/lib/action_dispatch/testing/test_request.rb +1 -1
  103. data/lib/action_dispatch/testing/test_response.rb +7 -0
  104. data/lib/action_pack/gem_version.rb +3 -3
  105. metadata +55 -13
  106. data/lib/action_controller/metal/responder.rb +0 -297
@@ -1,297 +0,0 @@
1
- require 'active_support/json'
2
-
3
- module ActionController #:nodoc:
4
- # Responsible for exposing a resource to different mime requests,
5
- # usually depending on the HTTP verb. The responder is triggered when
6
- # <code>respond_with</code> is called. The simplest case to study is a GET request:
7
- #
8
- # class PeopleController < ApplicationController
9
- # respond_to :html, :xml, :json
10
- #
11
- # def index
12
- # @people = Person.all
13
- # respond_with(@people)
14
- # end
15
- # end
16
- #
17
- # When a request comes in, for example for an XML response, three steps happen:
18
- #
19
- # 1) the responder searches for a template at people/index.xml;
20
- #
21
- # 2) if the template is not available, it will invoke <code>#to_xml</code> on the given resource;
22
- #
23
- # 3) if the responder does not <code>respond_to :to_xml</code>, call <code>#to_format</code> on it.
24
- #
25
- # === Builtin HTTP verb semantics
26
- #
27
- # The default \Rails responder holds semantics for each HTTP verb. Depending on the
28
- # content type, verb and the resource status, it will behave differently.
29
- #
30
- # Using \Rails default responder, a POST request for creating an object could
31
- # be written as:
32
- #
33
- # def create
34
- # @user = User.new(params[:user])
35
- # flash[:notice] = 'User was successfully created.' if @user.save
36
- # respond_with(@user)
37
- # end
38
- #
39
- # Which is exactly the same as:
40
- #
41
- # def create
42
- # @user = User.new(params[:user])
43
- #
44
- # respond_to do |format|
45
- # if @user.save
46
- # flash[:notice] = 'User was successfully created.'
47
- # format.html { redirect_to(@user) }
48
- # format.xml { render xml: @user, status: :created, location: @user }
49
- # else
50
- # format.html { render action: "new" }
51
- # format.xml { render xml: @user.errors, status: :unprocessable_entity }
52
- # end
53
- # end
54
- # end
55
- #
56
- # The same happens for PATCH/PUT and DELETE requests.
57
- #
58
- # === Nested resources
59
- #
60
- # You can supply nested resources as you do in <code>form_for</code> and <code>polymorphic_url</code>.
61
- # Consider the project has many tasks example. The create action for
62
- # TasksController would be like:
63
- #
64
- # def create
65
- # @project = Project.find(params[:project_id])
66
- # @task = @project.tasks.build(params[:task])
67
- # flash[:notice] = 'Task was successfully created.' if @task.save
68
- # respond_with(@project, @task)
69
- # end
70
- #
71
- # Giving several resources ensures that the responder will redirect to
72
- # <code>project_task_url</code> instead of <code>task_url</code>.
73
- #
74
- # Namespaced and singleton resources require a symbol to be given, as in
75
- # polymorphic urls. If a project has one manager which has many tasks, it
76
- # should be invoked as:
77
- #
78
- # respond_with(@project, :manager, @task)
79
- #
80
- # Note that if you give an array, it will be treated as a collection,
81
- # so the following is not equivalent:
82
- #
83
- # respond_with [@project, :manager, @task]
84
- #
85
- # === Custom options
86
- #
87
- # <code>respond_with</code> also allows you to pass options that are forwarded
88
- # to the underlying render call. Those options are only applied for success
89
- # scenarios. For instance, you can do the following in the create method above:
90
- #
91
- # def create
92
- # @project = Project.find(params[:project_id])
93
- # @task = @project.tasks.build(params[:task])
94
- # flash[:notice] = 'Task was successfully created.' if @task.save
95
- # respond_with(@project, @task, status: 201)
96
- # end
97
- #
98
- # This will return status 201 if the task was saved successfully. If not,
99
- # it will simply ignore the given options and return status 422 and the
100
- # resource errors. You can also override the location to redirect to:
101
- #
102
- # respond_with(@project, location: root_path)
103
- #
104
- # To customize the failure scenario, you can pass a block to
105
- # <code>respond_with</code>:
106
- #
107
- # def create
108
- # @project = Project.find(params[:project_id])
109
- # @task = @project.tasks.build(params[:task])
110
- # respond_with(@project, @task, status: 201) do |format|
111
- # if @task.save
112
- # flash[:notice] = 'Task was successfully created.'
113
- # else
114
- # format.html { render "some_special_template" }
115
- # end
116
- # end
117
- # end
118
- #
119
- # Using <code>respond_with</code> with a block follows the same syntax as <code>respond_to</code>.
120
- class Responder
121
- attr_reader :controller, :request, :format, :resource, :resources, :options
122
-
123
- DEFAULT_ACTIONS_FOR_VERBS = {
124
- :post => :new,
125
- :patch => :edit,
126
- :put => :edit
127
- }
128
-
129
- def initialize(controller, resources, options={})
130
- @controller = controller
131
- @request = @controller.request
132
- @format = @controller.formats.first
133
- @resource = resources.last
134
- @resources = resources
135
- @options = options
136
- @action = options.delete(:action)
137
- @default_response = options.delete(:default_response)
138
- end
139
-
140
- delegate :head, :render, :redirect_to, :to => :controller
141
- delegate :get?, :post?, :patch?, :put?, :delete?, :to => :request
142
-
143
- # Undefine :to_json and :to_yaml since it's defined on Object
144
- undef_method(:to_json) if method_defined?(:to_json)
145
- undef_method(:to_yaml) if method_defined?(:to_yaml)
146
-
147
- # Initializes a new responder and invokes the proper format. If the format is
148
- # not defined, call to_format.
149
- #
150
- def self.call(*args)
151
- new(*args).respond
152
- end
153
-
154
- # Main entry point for responder responsible to dispatch to the proper format.
155
- #
156
- def respond
157
- method = "to_#{format}"
158
- respond_to?(method) ? send(method) : to_format
159
- end
160
-
161
- # HTML format does not render the resource, it always attempt to render a
162
- # template.
163
- #
164
- def to_html
165
- default_render
166
- rescue ActionView::MissingTemplate => e
167
- navigation_behavior(e)
168
- end
169
-
170
- # to_js simply tries to render a template. If no template is found, raises the error.
171
- def to_js
172
- default_render
173
- end
174
-
175
- # All other formats follow the procedure below. First we try to render a
176
- # template, if the template is not available, we verify if the resource
177
- # responds to :to_format and display it.
178
- #
179
- def to_format
180
- if get? || !has_errors? || response_overridden?
181
- default_render
182
- else
183
- display_errors
184
- end
185
- rescue ActionView::MissingTemplate => e
186
- api_behavior(e)
187
- end
188
-
189
- protected
190
-
191
- # This is the common behavior for formats associated with browsing, like :html, :iphone and so forth.
192
- def navigation_behavior(error)
193
- if get?
194
- raise error
195
- elsif has_errors? && default_action
196
- render :action => default_action
197
- else
198
- redirect_to navigation_location
199
- end
200
- end
201
-
202
- # This is the common behavior for formats associated with APIs, such as :xml and :json.
203
- def api_behavior(error)
204
- raise error unless resourceful?
205
- raise MissingRenderer.new(format) unless has_renderer?
206
-
207
- if get?
208
- display resource
209
- elsif post?
210
- display resource, :status => :created, :location => api_location
211
- else
212
- head :no_content
213
- end
214
- end
215
-
216
- # Checks whether the resource responds to the current format or not.
217
- #
218
- def resourceful?
219
- resource.respond_to?("to_#{format}")
220
- end
221
-
222
- # Returns the resource location by retrieving it from the options or
223
- # returning the resources array.
224
- #
225
- def resource_location
226
- options[:location] || resources
227
- end
228
- alias :navigation_location :resource_location
229
- alias :api_location :resource_location
230
-
231
- # If a response block was given, use it, otherwise call render on
232
- # controller.
233
- #
234
- def default_render
235
- if @default_response
236
- @default_response.call(options)
237
- else
238
- controller.default_render(options)
239
- end
240
- end
241
-
242
- # Display is just a shortcut to render a resource with the current format.
243
- #
244
- # display @user, status: :ok
245
- #
246
- # For XML requests it's equivalent to:
247
- #
248
- # render xml: @user, status: :ok
249
- #
250
- # Options sent by the user are also used:
251
- #
252
- # respond_with(@user, status: :created)
253
- # display(@user, status: :ok)
254
- #
255
- # Results in:
256
- #
257
- # render xml: @user, status: :created
258
- #
259
- def display(resource, given_options={})
260
- controller.render given_options.merge!(options).merge!(format => resource)
261
- end
262
-
263
- def display_errors
264
- controller.render format => resource_errors, :status => :unprocessable_entity
265
- end
266
-
267
- # Check whether the resource has errors.
268
- #
269
- def has_errors?
270
- resource.respond_to?(:errors) && !resource.errors.empty?
271
- end
272
-
273
- # Check whether the necessary Renderer is available
274
- def has_renderer?
275
- Renderers::RENDERERS.include?(format)
276
- end
277
-
278
- # By default, render the <code>:edit</code> action for HTML requests with errors, unless
279
- # the verb was POST.
280
- #
281
- def default_action
282
- @action ||= DEFAULT_ACTIONS_FOR_VERBS[request.request_method_symbol]
283
- end
284
-
285
- def resource_errors
286
- respond_to?("#{format}_resource_errors", true) ? send("#{format}_resource_errors") : resource.errors
287
- end
288
-
289
- def json_resource_errors
290
- {:errors => resource.errors}
291
- end
292
-
293
- def response_overridden?
294
- @default_response.present?
295
- end
296
- end
297
- end