actionpack 4.1.16 → 4.2.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +163 -690
- data/README.rdoc +7 -2
- data/lib/abstract_controller/base.rb +16 -6
- data/lib/abstract_controller/callbacks.rb +28 -51
- data/lib/abstract_controller/helpers.rb +0 -3
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +1 -7
- data/lib/abstract_controller/url_for.rb +1 -1
- data/lib/action_controller.rb +1 -0
- data/lib/action_controller/base.rb +2 -1
- data/lib/action_controller/caching.rb +1 -1
- data/lib/action_controller/caching/fragments.rb +7 -1
- data/lib/action_controller/log_subscriber.rb +26 -25
- data/lib/action_controller/metal.rb +11 -7
- data/lib/action_controller/metal/conditional_get.rb +31 -6
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/force_ssl.rb +1 -1
- data/lib/action_controller/metal/head.rb +2 -0
- data/lib/action_controller/metal/http_authentication.rb +3 -15
- data/lib/action_controller/metal/instrumentation.rb +4 -7
- data/lib/action_controller/metal/live.rb +57 -6
- data/lib/action_controller/metal/mime_responds.rb +17 -227
- data/lib/action_controller/metal/redirecting.rb +14 -8
- data/lib/action_controller/metal/renderers.rb +19 -3
- data/lib/action_controller/metal/rendering.rb +2 -6
- data/lib/action_controller/metal/request_forgery_protection.rb +75 -7
- data/lib/action_controller/metal/streaming.rb +1 -1
- data/lib/action_controller/metal/strong_parameters.rb +111 -11
- data/lib/action_controller/metal/url_for.rb +11 -12
- data/lib/action_controller/model_naming.rb +1 -1
- data/lib/action_controller/railtie.rb +4 -0
- data/lib/action_controller/test_case.rb +87 -75
- data/lib/action_dispatch/http/cache.rb +1 -1
- data/lib/action_dispatch/http/filter_parameters.rb +2 -2
- data/lib/action_dispatch/http/headers.rb +43 -9
- data/lib/action_dispatch/http/mime_negotiation.rb +10 -4
- data/lib/action_dispatch/http/mime_type.rb +2 -16
- data/lib/action_dispatch/http/parameter_filter.rb +1 -1
- data/lib/action_dispatch/http/parameters.rb +11 -26
- data/lib/action_dispatch/http/request.rb +30 -10
- data/lib/action_dispatch/http/response.rb +52 -17
- data/lib/action_dispatch/http/upload.rb +3 -8
- data/lib/action_dispatch/http/url.rb +87 -70
- data/lib/action_dispatch/journey/formatter.rb +18 -17
- data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
- data/lib/action_dispatch/journey/gtg/transition_table.rb +18 -26
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
- data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
- data/lib/action_dispatch/journey/nodes/node.rb +4 -0
- data/lib/action_dispatch/journey/parser.rb +52 -60
- data/lib/action_dispatch/journey/parser.y +11 -10
- data/lib/action_dispatch/journey/path/pattern.rb +16 -19
- data/lib/action_dispatch/journey/route.rb +3 -18
- data/lib/action_dispatch/journey/router.rb +34 -65
- data/lib/action_dispatch/journey/router/strexp.rb +9 -6
- data/lib/action_dispatch/journey/routes.rb +0 -4
- data/lib/action_dispatch/journey/visitors.rb +81 -92
- data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
- data/lib/action_dispatch/middleware/cookies.rb +27 -31
- data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -3
- data/lib/action_dispatch/middleware/exception_wrapper.rb +19 -17
- data/lib/action_dispatch/middleware/flash.rb +7 -4
- data/lib/action_dispatch/middleware/public_exceptions.rb +13 -8
- data/lib/action_dispatch/middleware/remote_ip.rb +3 -3
- data/lib/action_dispatch/middleware/request_id.rb +1 -1
- data/lib/action_dispatch/middleware/session/cookie_store.rb +1 -1
- data/lib/action_dispatch/middleware/show_exceptions.rb +1 -0
- data/lib/action_dispatch/middleware/static.rb +22 -23
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +22 -18
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +36 -8
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +2 -8
- data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -24
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +0 -1
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +119 -63
- data/lib/action_dispatch/routing/endpoint.rb +10 -0
- data/lib/action_dispatch/routing/inspector.rb +4 -11
- data/lib/action_dispatch/routing/mapper.rb +399 -278
- data/lib/action_dispatch/routing/polymorphic_routes.rb +190 -78
- data/lib/action_dispatch/routing/redirection.rb +10 -12
- data/lib/action_dispatch/routing/route_set.rb +224 -177
- data/lib/action_dispatch/routing/url_for.rb +9 -4
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
- data/lib/action_dispatch/testing/assertions/response.rb +2 -7
- data/lib/action_dispatch/testing/assertions/routing.rb +9 -9
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
- data/lib/action_dispatch/testing/integration.rb +15 -18
- data/lib/action_dispatch/testing/test_request.rb +1 -1
- data/lib/action_dispatch/testing/test_response.rb +5 -1
- data/lib/action_pack/gem_version.rb +3 -3
- metadata +57 -15
- data/lib/action_controller/metal/responder.rb +0 -297
@@ -1,135 +1,3 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support/deprecation'
|
2
2
|
|
3
|
-
|
4
|
-
module Assertions
|
5
|
-
# Pair of assertions to testing elements in the HTML output of the response.
|
6
|
-
module TagAssertions
|
7
|
-
# Asserts that there is a tag/node/element in the body of the response
|
8
|
-
# that meets all of the given conditions. The +conditions+ parameter must
|
9
|
-
# be a hash of any of the following keys (all are optional):
|
10
|
-
#
|
11
|
-
# * <tt>:tag</tt>: the node type must match the corresponding value
|
12
|
-
# * <tt>:attributes</tt>: a hash. The node's attributes must match the
|
13
|
-
# corresponding values in the hash.
|
14
|
-
# * <tt>:parent</tt>: a hash. The node's parent must match the
|
15
|
-
# corresponding hash.
|
16
|
-
# * <tt>:child</tt>: a hash. At least one of the node's immediate children
|
17
|
-
# must meet the criteria described by the hash.
|
18
|
-
# * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
|
19
|
-
# meet the criteria described by the hash.
|
20
|
-
# * <tt>:descendant</tt>: a hash. At least one of the node's descendants
|
21
|
-
# must meet the criteria described by the hash.
|
22
|
-
# * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
|
23
|
-
# meet the criteria described by the hash.
|
24
|
-
# * <tt>:after</tt>: a hash. The node must be after any sibling meeting
|
25
|
-
# the criteria described by the hash, and at least one sibling must match.
|
26
|
-
# * <tt>:before</tt>: a hash. The node must be before any sibling meeting
|
27
|
-
# the criteria described by the hash, and at least one sibling must match.
|
28
|
-
# * <tt>:children</tt>: a hash, for counting children of a node. Accepts
|
29
|
-
# the keys:
|
30
|
-
# * <tt>:count</tt>: either a number or a range which must equal (or
|
31
|
-
# include) the number of children that match.
|
32
|
-
# * <tt>:less_than</tt>: the number of matching children must be less
|
33
|
-
# than this number.
|
34
|
-
# * <tt>:greater_than</tt>: the number of matching children must be
|
35
|
-
# greater than this number.
|
36
|
-
# * <tt>:only</tt>: another hash consisting of the keys to use
|
37
|
-
# to match on the children, and only matching children will be
|
38
|
-
# counted.
|
39
|
-
# * <tt>:content</tt>: the textual content of the node must match the
|
40
|
-
# given value. This will not match HTML tags in the body of a
|
41
|
-
# tag--only text.
|
42
|
-
#
|
43
|
-
# Conditions are matched using the following algorithm:
|
44
|
-
#
|
45
|
-
# * if the condition is a string, it must be a substring of the value.
|
46
|
-
# * if the condition is a regexp, it must match the value.
|
47
|
-
# * if the condition is a number, the value must match number.to_s.
|
48
|
-
# * if the condition is +true+, the value must not be +nil+.
|
49
|
-
# * if the condition is +false+ or +nil+, the value must be +nil+.
|
50
|
-
#
|
51
|
-
# # Assert that there is a "span" tag
|
52
|
-
# assert_tag tag: "span"
|
53
|
-
#
|
54
|
-
# # Assert that there is a "span" tag with id="x"
|
55
|
-
# assert_tag tag: "span", attributes: { id: "x" }
|
56
|
-
#
|
57
|
-
# # Assert that there is a "span" tag using the short-hand
|
58
|
-
# assert_tag :span
|
59
|
-
#
|
60
|
-
# # Assert that there is a "span" tag with id="x" using the short-hand
|
61
|
-
# assert_tag :span, attributes: { id: "x" }
|
62
|
-
#
|
63
|
-
# # Assert that there is a "span" inside of a "div"
|
64
|
-
# assert_tag tag: "span", parent: { tag: "div" }
|
65
|
-
#
|
66
|
-
# # Assert that there is a "span" somewhere inside a table
|
67
|
-
# assert_tag tag: "span", ancestor: { tag: "table" }
|
68
|
-
#
|
69
|
-
# # Assert that there is a "span" with at least one "em" child
|
70
|
-
# assert_tag tag: "span", child: { tag: "em" }
|
71
|
-
#
|
72
|
-
# # Assert that there is a "span" containing a (possibly nested)
|
73
|
-
# # "strong" tag.
|
74
|
-
# assert_tag tag: "span", descendant: { tag: "strong" }
|
75
|
-
#
|
76
|
-
# # Assert that there is a "span" containing between 2 and 4 "em" tags
|
77
|
-
# # as immediate children
|
78
|
-
# assert_tag tag: "span",
|
79
|
-
# children: { count: 2..4, only: { tag: "em" } }
|
80
|
-
#
|
81
|
-
# # Get funky: assert that there is a "div", with an "ul" ancestor
|
82
|
-
# # and an "li" parent (with "class" = "enum"), and containing a
|
83
|
-
# # "span" descendant that contains text matching /hello world/
|
84
|
-
# assert_tag tag: "div",
|
85
|
-
# ancestor: { tag: "ul" },
|
86
|
-
# parent: { tag: "li",
|
87
|
-
# attributes: { class: "enum" } },
|
88
|
-
# descendant: { tag: "span",
|
89
|
-
# child: /hello world/ }
|
90
|
-
#
|
91
|
-
# <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
|
92
|
-
# with well-formed XHTML. They recognize a few tags as implicitly self-closing
|
93
|
-
# (like br and hr and such) but will not work correctly with tags
|
94
|
-
# that allow optional closing tags (p, li, td). <em>You must explicitly
|
95
|
-
# close all of your tags to use these assertions.</em>
|
96
|
-
def assert_tag(*opts)
|
97
|
-
opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first
|
98
|
-
tag = find_tag(opts)
|
99
|
-
assert tag, "expected tag, but no tag found matching #{opts.inspect} in:\n#{@response.body.inspect}"
|
100
|
-
end
|
101
|
-
|
102
|
-
# Identical to +assert_tag+, but asserts that a matching tag does _not_
|
103
|
-
# exist. (See +assert_tag+ for a full discussion of the syntax.)
|
104
|
-
#
|
105
|
-
# # Assert that there is not a "div" containing a "p"
|
106
|
-
# assert_no_tag tag: "div", descendant: { tag: "p" }
|
107
|
-
#
|
108
|
-
# # Assert that an unordered list is empty
|
109
|
-
# assert_no_tag tag: "ul", descendant: { tag: "li" }
|
110
|
-
#
|
111
|
-
# # Assert that there is not a "p" tag with between 1 to 3 "img" tags
|
112
|
-
# # as immediate children
|
113
|
-
# assert_no_tag tag: "p",
|
114
|
-
# children: { count: 1..3, only: { tag: "img" } }
|
115
|
-
def assert_no_tag(*opts)
|
116
|
-
opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first
|
117
|
-
tag = find_tag(opts)
|
118
|
-
assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}"
|
119
|
-
end
|
120
|
-
|
121
|
-
def find_tag(conditions)
|
122
|
-
html_document.find(conditions)
|
123
|
-
end
|
124
|
-
|
125
|
-
def find_all_tag(conditions)
|
126
|
-
html_document.find_all(conditions)
|
127
|
-
end
|
128
|
-
|
129
|
-
def html_document
|
130
|
-
xml = @response.content_type =~ /xml$/
|
131
|
-
@html_document ||= HTML::Document.new(@response.body, false, xml)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
3
|
+
ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::TagAssertions has been has been extracted to the rails-dom-testing gem.")
|
@@ -189,8 +189,8 @@ module ActionDispatch
|
|
189
189
|
# This makes app.url_for and app.foo_path available in the console
|
190
190
|
if app.respond_to?(:routes)
|
191
191
|
singleton_class.class_eval do
|
192
|
-
include app.routes.url_helpers
|
193
|
-
include app.routes.mounted_helpers
|
192
|
+
include app.routes.url_helpers
|
193
|
+
include app.routes.mounted_helpers
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -201,7 +201,7 @@ module ActionDispatch
|
|
201
201
|
@url_options ||= default_url_options.dup.tap do |url_options|
|
202
202
|
url_options.reverse_merge!(controller.url_options) if controller
|
203
203
|
|
204
|
-
if @app.respond_to?(:routes)
|
204
|
+
if @app.respond_to?(:routes)
|
205
205
|
url_options.reverse_merge!(@app.routes.default_url_options)
|
206
206
|
end
|
207
207
|
|
@@ -270,12 +270,6 @@ module ActionDispatch
|
|
270
270
|
path = location.query ? "#{location.path}?#{location.query}" : location.path
|
271
271
|
end
|
272
272
|
|
273
|
-
unless ActionController::Base < ActionController::Testing
|
274
|
-
ActionController::Base.class_eval do
|
275
|
-
include ActionController::Testing
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
273
|
hostname, port = host.split(':')
|
280
274
|
|
281
275
|
env = {
|
@@ -300,18 +294,12 @@ module ActionDispatch
|
|
300
294
|
|
301
295
|
# NOTE: rack-test v0.5 doesn't build a default uri correctly
|
302
296
|
# Make sure requested path is always a full uri
|
303
|
-
|
304
|
-
uri.scheme ||= env['rack.url_scheme']
|
305
|
-
uri.host ||= env['SERVER_NAME']
|
306
|
-
uri.port ||= env['SERVER_PORT'].try(:to_i)
|
307
|
-
uri += path
|
308
|
-
|
309
|
-
session.request(uri.to_s, env)
|
297
|
+
session.request(build_full_uri(path, env), env)
|
310
298
|
|
311
299
|
@request_count += 1
|
312
300
|
@request = ActionDispatch::Request.new(session.last_request.env)
|
313
301
|
response = _mock_session.last_response
|
314
|
-
@response = ActionDispatch::TestResponse.
|
302
|
+
@response = ActionDispatch::TestResponse.new(response.status, response.headers, response.body)
|
315
303
|
@html_document = nil
|
316
304
|
@url_options = nil
|
317
305
|
|
@@ -319,6 +307,10 @@ module ActionDispatch
|
|
319
307
|
|
320
308
|
return response.status
|
321
309
|
end
|
310
|
+
|
311
|
+
def build_full_uri(path, env)
|
312
|
+
"#{env['rack.url_scheme']}://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{path}"
|
313
|
+
end
|
322
314
|
end
|
323
315
|
|
324
316
|
module Runner
|
@@ -338,6 +330,7 @@ module ActionDispatch
|
|
338
330
|
xml_http_request xhr get_via_redirect post_via_redirect).each do |method|
|
339
331
|
define_method(method) do |*args|
|
340
332
|
reset! unless integration_session
|
333
|
+
reset_template_assertion
|
341
334
|
# reset the html_document variable, but only for new get/post calls
|
342
335
|
@html_document = nil unless method == 'cookies' || method == 'assigns'
|
343
336
|
integration_session.__send__(method, *args).tap do
|
@@ -356,7 +349,7 @@ module ActionDispatch
|
|
356
349
|
# By default, a single session is automatically created for you, but you
|
357
350
|
# can use this method to open multiple sessions that ought to be tested
|
358
351
|
# simultaneously.
|
359
|
-
def open_session
|
352
|
+
def open_session
|
360
353
|
dup.tap do |session|
|
361
354
|
yield session if block_given?
|
362
355
|
end
|
@@ -502,5 +495,9 @@ module ActionDispatch
|
|
502
495
|
reset! unless integration_session
|
503
496
|
integration_session.url_options
|
504
497
|
end
|
498
|
+
|
499
|
+
def document_root_element
|
500
|
+
html_document.root
|
501
|
+
end
|
505
502
|
end
|
506
503
|
end
|
@@ -7,7 +7,11 @@ module ActionDispatch
|
|
7
7
|
# See Response for more information on controller response objects.
|
8
8
|
class TestResponse < Response
|
9
9
|
def self.from_response(response)
|
10
|
-
new
|
10
|
+
new.tap do |resp|
|
11
|
+
resp.status = response.status
|
12
|
+
resp.headers = response.headers
|
13
|
+
resp.body = response.body
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
# Was the response successful?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.2.0.beta1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
26
|
+
version: 4.2.0.beta1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.6.0.beta
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.6.0.beta
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rack-test
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,34 +52,74 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.6.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails-deprecated_sanitizer
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.0.2
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.0.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rails-dom-testing
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.0'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.0.2
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.0'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.0.2
|
55
95
|
- !ruby/object:Gem::Dependency
|
56
96
|
name: actionview
|
57
97
|
requirement: !ruby/object:Gem::Requirement
|
58
98
|
requirements:
|
59
99
|
- - '='
|
60
100
|
- !ruby/object:Gem::Version
|
61
|
-
version: 4.
|
101
|
+
version: 4.2.0.beta1
|
62
102
|
type: :runtime
|
63
103
|
prerelease: false
|
64
104
|
version_requirements: !ruby/object:Gem::Requirement
|
65
105
|
requirements:
|
66
106
|
- - '='
|
67
107
|
- !ruby/object:Gem::Version
|
68
|
-
version: 4.
|
108
|
+
version: 4.2.0.beta1
|
69
109
|
- !ruby/object:Gem::Dependency
|
70
110
|
name: activemodel
|
71
111
|
requirement: !ruby/object:Gem::Requirement
|
72
112
|
requirements:
|
73
113
|
- - '='
|
74
114
|
- !ruby/object:Gem::Version
|
75
|
-
version: 4.
|
115
|
+
version: 4.2.0.beta1
|
76
116
|
type: :development
|
77
117
|
prerelease: false
|
78
118
|
version_requirements: !ruby/object:Gem::Requirement
|
79
119
|
requirements:
|
80
120
|
- - '='
|
81
121
|
- !ruby/object:Gem::Version
|
82
|
-
version: 4.
|
122
|
+
version: 4.2.0.beta1
|
83
123
|
description: Web apps on Rails. Simple, battle-tested conventions for building and
|
84
124
|
testing MVC web applications. Works with any Rack-compatible server.
|
85
125
|
email: david@loudthinking.com
|
@@ -110,6 +150,7 @@ files:
|
|
110
150
|
- lib/action_controller/metal/conditional_get.rb
|
111
151
|
- lib/action_controller/metal/cookies.rb
|
112
152
|
- lib/action_controller/metal/data_streaming.rb
|
153
|
+
- lib/action_controller/metal/etag_with_template_digest.rb
|
113
154
|
- lib/action_controller/metal/exceptions.rb
|
114
155
|
- lib/action_controller/metal/flash.rb
|
115
156
|
- lib/action_controller/metal/force_ssl.rb
|
@@ -128,7 +169,6 @@ files:
|
|
128
169
|
- lib/action_controller/metal/rendering.rb
|
129
170
|
- lib/action_controller/metal/request_forgery_protection.rb
|
130
171
|
- lib/action_controller/metal/rescue.rb
|
131
|
-
- lib/action_controller/metal/responder.rb
|
132
172
|
- lib/action_controller/metal/streaming.rb
|
133
173
|
- lib/action_controller/metal/strong_parameters.rb
|
134
174
|
- lib/action_controller/metal/testing.rb
|
@@ -201,7 +241,8 @@ files:
|
|
201
241
|
- lib/action_dispatch/middleware/templates/rescues/_source.erb
|
202
242
|
- lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
|
203
243
|
- lib/action_dispatch/middleware/templates/rescues/_trace.text.erb
|
204
|
-
- lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
|
244
|
+
- lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb
|
245
|
+
- lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb
|
205
246
|
- lib/action_dispatch/middleware/templates/rescues/layout.erb
|
206
247
|
- lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb
|
207
248
|
- lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb
|
@@ -217,6 +258,7 @@ files:
|
|
217
258
|
- lib/action_dispatch/request/session.rb
|
218
259
|
- lib/action_dispatch/request/utils.rb
|
219
260
|
- lib/action_dispatch/routing.rb
|
261
|
+
- lib/action_dispatch/routing/endpoint.rb
|
220
262
|
- lib/action_dispatch/routing/inspector.rb
|
221
263
|
- lib/action_dispatch/routing/mapper.rb
|
222
264
|
- lib/action_dispatch/routing/polymorphic_routes.rb
|
@@ -252,13 +294,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
252
294
|
version: 1.9.3
|
253
295
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
254
296
|
requirements:
|
255
|
-
- - "
|
297
|
+
- - ">"
|
256
298
|
- !ruby/object:Gem::Version
|
257
|
-
version:
|
299
|
+
version: 1.3.1
|
258
300
|
requirements:
|
259
301
|
- none
|
260
302
|
rubyforge_project:
|
261
|
-
rubygems_version: 2.
|
303
|
+
rubygems_version: 2.2.2
|
262
304
|
signing_key:
|
263
305
|
specification_version: 4
|
264
306
|
summary: Web-flow and rendering framework putting the VC in MVC (part of Rails).
|
@@ -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
|