actionpack 3.2.19 → 4.2.11.3

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 (244) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +412 -503
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +11 -294
  5. data/lib/abstract_controller/asset_paths.rb +2 -2
  6. data/lib/abstract_controller/base.rb +52 -18
  7. data/lib/abstract_controller/callbacks.rb +87 -89
  8. data/lib/abstract_controller/collector.rb +17 -3
  9. data/lib/abstract_controller/helpers.rb +41 -14
  10. data/lib/abstract_controller/logger.rb +1 -2
  11. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  12. data/lib/abstract_controller/rendering.rb +65 -118
  13. data/lib/abstract_controller/translation.rb +16 -1
  14. data/lib/abstract_controller/url_for.rb +7 -7
  15. data/lib/abstract_controller.rb +2 -10
  16. data/lib/action_controller/base.rb +61 -28
  17. data/lib/action_controller/caching/fragments.rb +30 -54
  18. data/lib/action_controller/caching.rb +38 -35
  19. data/lib/action_controller/log_subscriber.rb +35 -18
  20. data/lib/action_controller/metal/conditional_get.rb +103 -34
  21. data/lib/action_controller/metal/data_streaming.rb +20 -26
  22. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  23. data/lib/action_controller/metal/exceptions.rb +19 -6
  24. data/lib/action_controller/metal/flash.rb +41 -9
  25. data/lib/action_controller/metal/force_ssl.rb +70 -12
  26. data/lib/action_controller/metal/head.rb +30 -7
  27. data/lib/action_controller/metal/helpers.rb +11 -11
  28. data/lib/action_controller/metal/hide_actions.rb +0 -1
  29. data/lib/action_controller/metal/http_authentication.rb +140 -94
  30. data/lib/action_controller/metal/implicit_render.rb +1 -1
  31. data/lib/action_controller/metal/instrumentation.rb +11 -7
  32. data/lib/action_controller/metal/live.rb +328 -0
  33. data/lib/action_controller/metal/mime_responds.rb +161 -152
  34. data/lib/action_controller/metal/params_wrapper.rb +126 -81
  35. data/lib/action_controller/metal/rack_delegation.rb +10 -4
  36. data/lib/action_controller/metal/redirecting.rb +44 -41
  37. data/lib/action_controller/metal/renderers.rb +48 -19
  38. data/lib/action_controller/metal/rendering.rb +46 -11
  39. data/lib/action_controller/metal/request_forgery_protection.rb +250 -29
  40. data/lib/action_controller/metal/streaming.rb +30 -38
  41. data/lib/action_controller/metal/strong_parameters.rb +669 -0
  42. data/lib/action_controller/metal/testing.rb +12 -18
  43. data/lib/action_controller/metal/url_for.rb +31 -29
  44. data/lib/action_controller/metal.rb +31 -40
  45. data/lib/action_controller/model_naming.rb +12 -0
  46. data/lib/action_controller/railtie.rb +38 -18
  47. data/lib/action_controller/railties/helpers.rb +22 -0
  48. data/lib/action_controller/test_case.rb +359 -173
  49. data/lib/action_controller.rb +9 -16
  50. data/lib/action_dispatch/http/cache.rb +64 -11
  51. data/lib/action_dispatch/http/filter_parameters.rb +20 -10
  52. data/lib/action_dispatch/http/filter_redirect.rb +38 -0
  53. data/lib/action_dispatch/http/headers.rb +85 -17
  54. data/lib/action_dispatch/http/mime_negotiation.rb +55 -5
  55. data/lib/action_dispatch/http/mime_type.rb +167 -114
  56. data/lib/action_dispatch/http/mime_types.rb +2 -1
  57. data/lib/action_dispatch/http/parameter_filter.rb +44 -46
  58. data/lib/action_dispatch/http/parameters.rb +30 -46
  59. data/lib/action_dispatch/http/rack_cache.rb +2 -3
  60. data/lib/action_dispatch/http/request.rb +108 -45
  61. data/lib/action_dispatch/http/response.rb +247 -48
  62. data/lib/action_dispatch/http/upload.rb +60 -29
  63. data/lib/action_dispatch/http/url.rb +135 -45
  64. data/lib/action_dispatch/journey/backwards.rb +5 -0
  65. data/lib/action_dispatch/journey/formatter.rb +166 -0
  66. data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
  67. data/lib/action_dispatch/journey/gtg/simulator.rb +47 -0
  68. data/lib/action_dispatch/journey/gtg/transition_table.rb +157 -0
  69. data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
  70. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  71. data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
  72. data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
  73. data/lib/action_dispatch/journey/nodes/node.rb +128 -0
  74. data/lib/action_dispatch/journey/parser.rb +198 -0
  75. data/lib/action_dispatch/journey/parser.y +49 -0
  76. data/lib/action_dispatch/journey/parser_extras.rb +23 -0
  77. data/lib/action_dispatch/journey/path/pattern.rb +193 -0
  78. data/lib/action_dispatch/journey/route.rb +125 -0
  79. data/lib/action_dispatch/journey/router/strexp.rb +27 -0
  80. data/lib/action_dispatch/journey/router/utils.rb +93 -0
  81. data/lib/action_dispatch/journey/router.rb +144 -0
  82. data/lib/action_dispatch/journey/routes.rb +80 -0
  83. data/lib/action_dispatch/journey/scanner.rb +61 -0
  84. data/lib/action_dispatch/journey/visitors.rb +221 -0
  85. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  86. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  87. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  88. data/lib/action_dispatch/journey.rb +5 -0
  89. data/lib/action_dispatch/middleware/callbacks.rb +16 -11
  90. data/lib/action_dispatch/middleware/cookies.rb +346 -125
  91. data/lib/action_dispatch/middleware/debug_exceptions.rb +52 -24
  92. data/lib/action_dispatch/middleware/exception_wrapper.rb +75 -9
  93. data/lib/action_dispatch/middleware/flash.rb +85 -72
  94. data/lib/action_dispatch/middleware/params_parser.rb +16 -31
  95. data/lib/action_dispatch/middleware/public_exceptions.rb +39 -14
  96. data/lib/action_dispatch/middleware/reloader.rb +16 -7
  97. data/lib/action_dispatch/middleware/remote_ip.rb +132 -40
  98. data/lib/action_dispatch/middleware/request_id.rb +3 -7
  99. data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
  100. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  101. data/lib/action_dispatch/middleware/session/cookie_store.rb +84 -29
  102. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
  103. data/lib/action_dispatch/middleware/show_exceptions.rb +15 -44
  104. data/lib/action_dispatch/middleware/ssl.rb +72 -0
  105. data/lib/action_dispatch/middleware/stack.rb +6 -1
  106. data/lib/action_dispatch/middleware/static.rb +80 -23
  107. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +34 -0
  108. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  109. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +27 -0
  110. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  111. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  112. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  113. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  114. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +133 -5
  115. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  116. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  117. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  123. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  125. data/lib/action_dispatch/railtie.rb +19 -6
  126. data/lib/action_dispatch/request/session.rb +193 -0
  127. data/lib/action_dispatch/request/utils.rb +35 -0
  128. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  129. data/lib/action_dispatch/routing/inspector.rb +234 -0
  130. data/lib/action_dispatch/routing/mapper.rb +897 -436
  131. data/lib/action_dispatch/routing/polymorphic_routes.rb +213 -92
  132. data/lib/action_dispatch/routing/redirection.rb +97 -37
  133. data/lib/action_dispatch/routing/route_set.rb +432 -239
  134. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  135. data/lib/action_dispatch/routing/url_for.rb +63 -34
  136. data/lib/action_dispatch/routing.rb +57 -89
  137. data/lib/action_dispatch/testing/assertions/dom.rb +2 -36
  138. data/lib/action_dispatch/testing/assertions/response.rb +24 -38
  139. data/lib/action_dispatch/testing/assertions/routing.rb +55 -54
  140. data/lib/action_dispatch/testing/assertions/selector.rb +2 -434
  141. data/lib/action_dispatch/testing/assertions/tag.rb +2 -137
  142. data/lib/action_dispatch/testing/assertions.rb +11 -7
  143. data/lib/action_dispatch/testing/integration.rb +88 -72
  144. data/lib/action_dispatch/testing/test_process.rb +9 -6
  145. data/lib/action_dispatch/testing/test_request.rb +13 -9
  146. data/lib/action_dispatch/testing/test_response.rb +1 -5
  147. data/lib/action_dispatch.rb +24 -21
  148. data/lib/action_pack/gem_version.rb +15 -0
  149. data/lib/action_pack/version.rb +5 -7
  150. data/lib/action_pack.rb +1 -1
  151. metadata +181 -292
  152. data/lib/abstract_controller/layouts.rb +0 -423
  153. data/lib/abstract_controller/view_paths.rb +0 -96
  154. data/lib/action_controller/caching/actions.rb +0 -185
  155. data/lib/action_controller/caching/pages.rb +0 -187
  156. data/lib/action_controller/caching/sweeping.rb +0 -97
  157. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  158. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  159. data/lib/action_controller/deprecated.rb +0 -3
  160. data/lib/action_controller/metal/compatibility.rb +0 -65
  161. data/lib/action_controller/metal/responder.rb +0 -286
  162. data/lib/action_controller/metal/session_management.rb +0 -14
  163. data/lib/action_controller/railties/paths.rb +0 -25
  164. data/lib/action_controller/record_identifier.rb +0 -85
  165. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  166. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  167. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  168. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  169. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  170. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  171. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  172. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  173. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  174. data/lib/action_dispatch/middleware/head.rb +0 -18
  175. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  176. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  177. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  178. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  179. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  180. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  181. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  182. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  183. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  184. data/lib/action_view/asset_paths.rb +0 -142
  185. data/lib/action_view/base.rb +0 -220
  186. data/lib/action_view/buffers.rb +0 -43
  187. data/lib/action_view/context.rb +0 -36
  188. data/lib/action_view/flows.rb +0 -79
  189. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  190. data/lib/action_view/helpers/asset_paths.rb +0 -7
  191. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  192. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  193. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  194. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  195. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  196. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  197. data/lib/action_view/helpers/cache_helper.rb +0 -64
  198. data/lib/action_view/helpers/capture_helper.rb +0 -203
  199. data/lib/action_view/helpers/controller_helper.rb +0 -25
  200. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  201. data/lib/action_view/helpers/date_helper.rb +0 -1062
  202. data/lib/action_view/helpers/debug_helper.rb +0 -40
  203. data/lib/action_view/helpers/form_helper.rb +0 -1486
  204. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  205. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  206. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  207. data/lib/action_view/helpers/number_helper.rb +0 -622
  208. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  209. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  210. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  211. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  212. data/lib/action_view/helpers/tag_helper.rb +0 -160
  213. data/lib/action_view/helpers/text_helper.rb +0 -426
  214. data/lib/action_view/helpers/translation_helper.rb +0 -91
  215. data/lib/action_view/helpers/url_helper.rb +0 -693
  216. data/lib/action_view/helpers.rb +0 -60
  217. data/lib/action_view/locale/en.yml +0 -160
  218. data/lib/action_view/log_subscriber.rb +0 -28
  219. data/lib/action_view/lookup_context.rb +0 -254
  220. data/lib/action_view/path_set.rb +0 -89
  221. data/lib/action_view/railtie.rb +0 -55
  222. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  223. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  224. data/lib/action_view/renderer/renderer.rb +0 -54
  225. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  226. data/lib/action_view/renderer/template_renderer.rb +0 -94
  227. data/lib/action_view/template/error.rb +0 -128
  228. data/lib/action_view/template/handlers/builder.rb +0 -26
  229. data/lib/action_view/template/handlers/erb.rb +0 -125
  230. data/lib/action_view/template/handlers.rb +0 -50
  231. data/lib/action_view/template/resolver.rb +0 -272
  232. data/lib/action_view/template/text.rb +0 -30
  233. data/lib/action_view/template.rb +0 -337
  234. data/lib/action_view/test_case.rb +0 -245
  235. data/lib/action_view/testing/resolvers.rb +0 -50
  236. data/lib/action_view.rb +0 -84
  237. data/lib/sprockets/assets.rake +0 -99
  238. data/lib/sprockets/bootstrap.rb +0 -37
  239. data/lib/sprockets/compressors.rb +0 -83
  240. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  241. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  242. data/lib/sprockets/helpers.rb +0 -6
  243. data/lib/sprockets/railtie.rb +0 -62
  244. data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,337 +0,0 @@
1
- require 'active_support/core_ext/array/wrap'
2
- require 'active_support/core_ext/object/blank'
3
- require 'active_support/core_ext/object/try'
4
- require 'active_support/core_ext/kernel/singleton_class'
5
- require 'thread'
6
-
7
- module ActionView
8
- # = Action View Template
9
- class Template
10
- extend ActiveSupport::Autoload
11
-
12
- # === Encodings in ActionView::Template
13
- #
14
- # ActionView::Template is one of a few sources of potential
15
- # encoding issues in Rails. This is because the source for
16
- # templates are usually read from disk, and Ruby (like most
17
- # encoding-aware programming languages) assumes that the
18
- # String retrieved through File IO is encoded in the
19
- # <tt>default_external</tt> encoding. In Rails, the default
20
- # <tt>default_external</tt> encoding is UTF-8.
21
- #
22
- # As a result, if a user saves their template as ISO-8859-1
23
- # (for instance, using a non-Unicode-aware text editor),
24
- # and uses characters outside of the ASCII range, their
25
- # users will see diamonds with question marks in them in
26
- # the browser.
27
- #
28
- # For the rest of this documentation, when we say "UTF-8",
29
- # we mean "UTF-8 or whatever the default_internal encoding
30
- # is set to". By default, it will be UTF-8.
31
- #
32
- # To mitigate this problem, we use a few strategies:
33
- # 1. If the source is not valid UTF-8, we raise an exception
34
- # when the template is compiled to alert the user
35
- # to the problem.
36
- # 2. The user can specify the encoding using Ruby-style
37
- # encoding comments in any template engine. If such
38
- # a comment is supplied, Rails will apply that encoding
39
- # to the resulting compiled source returned by the
40
- # template handler.
41
- # 3. In all cases, we transcode the resulting String to
42
- # the UTF-8.
43
- #
44
- # This means that other parts of Rails can always assume
45
- # that templates are encoded in UTF-8, even if the original
46
- # source of the template was not UTF-8.
47
- #
48
- # From a user's perspective, the easiest thing to do is
49
- # to save your templates as UTF-8. If you do this, you
50
- # do not need to do anything else for things to "just work".
51
- #
52
- # === Instructions for template handlers
53
- #
54
- # The easiest thing for you to do is to simply ignore
55
- # encodings. Rails will hand you the template source
56
- # as the default_internal (generally UTF-8), raising
57
- # an exception for the user before sending the template
58
- # to you if it could not determine the original encoding.
59
- #
60
- # For the greatest simplicity, you can support only
61
- # UTF-8 as the <tt>default_internal</tt>. This means
62
- # that from the perspective of your handler, the
63
- # entire pipeline is just UTF-8.
64
- #
65
- # === Advanced: Handlers with alternate metadata sources
66
- #
67
- # If you want to provide an alternate mechanism for
68
- # specifying encodings (like ERB does via <%# encoding: ... %>),
69
- # you may indicate that you will handle encodings yourself
70
- # by implementing <tt>self.handles_encoding?</tt>
71
- # on your handler.
72
- #
73
- # If you do, Rails will not try to encode the String
74
- # into the default_internal, passing you the unaltered
75
- # bytes tagged with the assumed encoding (from
76
- # default_external).
77
- #
78
- # In this case, make sure you return a String from
79
- # your handler encoded in the default_internal. Since
80
- # you are handling out-of-band metadata, you are
81
- # also responsible for alerting the user to any
82
- # problems with converting the user's data to
83
- # the <tt>default_internal</tt>.
84
- #
85
- # To do so, simply raise the raise +WrongEncodingError+
86
- # as follows:
87
- #
88
- # raise WrongEncodingError.new(
89
- # problematic_string,
90
- # expected_encoding
91
- # )
92
-
93
- eager_autoload do
94
- autoload :Error
95
- autoload :Handlers
96
- autoload :Text
97
- end
98
-
99
- extend Template::Handlers
100
-
101
- attr_accessor :locals, :formats, :virtual_path
102
-
103
- attr_reader :source, :identifier, :handler, :original_encoding, :updated_at
104
-
105
- # This finalizer is needed (and exactly with a proc inside another proc)
106
- # otherwise templates leak in development.
107
- Finalizer = proc do |method_name, mod|
108
- proc do
109
- mod.module_eval do
110
- remove_possible_method method_name
111
- end
112
- end
113
- end
114
-
115
- def initialize(source, identifier, handler, details)
116
- format = details[:format] || (handler.default_format if handler.respond_to?(:default_format))
117
-
118
- @source = source
119
- @identifier = identifier
120
- @handler = handler
121
- @compiled = false
122
- @original_encoding = nil
123
- @locals = details[:locals] || []
124
- @virtual_path = details[:virtual_path]
125
- @updated_at = details[:updated_at] || Time.now
126
- @formats = Array.wrap(format).map { |f| f.is_a?(Mime::Type) ? f.ref : f }
127
- @compile_mutex = Mutex.new
128
- end
129
-
130
- # Returns if the underlying handler supports streaming. If so,
131
- # a streaming buffer *may* be passed when it start rendering.
132
- def supports_streaming?
133
- handler.respond_to?(:supports_streaming?) && handler.supports_streaming?
134
- end
135
-
136
- # Render a template. If the template was not compiled yet, it is done
137
- # exactly before rendering.
138
- #
139
- # This method is instrumented as "!render_template.action_view". Notice that
140
- # we use a bang in this instrumentation because you don't want to
141
- # consume this in production. This is only slow if it's being listened to.
142
- def render(view, locals, buffer=nil, &block)
143
- ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do
144
- compile!(view)
145
- view.send(method_name, locals, buffer, &block)
146
- end
147
- rescue Exception => e
148
- handle_render_error(view, e)
149
- end
150
-
151
- def mime_type
152
- @mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first
153
- end
154
-
155
- # Receives a view object and return a template similar to self by using @virtual_path.
156
- #
157
- # This method is useful if you have a template object but it does not contain its source
158
- # anymore since it was already compiled. In such cases, all you need to do is to call
159
- # refresh passing in the view object.
160
- #
161
- # Notice this method raises an error if the template to be refreshed does not have a
162
- # virtual path set (true just for inline templates).
163
- def refresh(view)
164
- raise "A template needs to have a virtual path in order to be refreshed" unless @virtual_path
165
- lookup = view.lookup_context
166
- pieces = @virtual_path.split("/")
167
- name = pieces.pop
168
- partial = !!name.sub!(/^_/, "")
169
- lookup.disable_cache do
170
- lookup.find_template(name, [ pieces.join('/') ], partial, @locals)
171
- end
172
- end
173
-
174
- def inspect
175
- @inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", '') : identifier
176
- end
177
-
178
- # This method is responsible for properly setting the encoding of the
179
- # source. Until this point, we assume that the source is BINARY data.
180
- # If no additional information is supplied, we assume the encoding is
181
- # the same as <tt>Encoding.default_external</tt>.
182
- #
183
- # The user can also specify the encoding via a comment on the first
184
- # line of the template (# encoding: NAME-OF-ENCODING). This will work
185
- # with any template engine, as we process out the encoding comment
186
- # before passing the source on to the template engine, leaving a
187
- # blank line in its stead.
188
- def encode!
189
- return unless source.encoding_aware? && source.encoding == Encoding::BINARY
190
-
191
- # Look for # encoding: *. If we find one, we'll encode the
192
- # String in that encoding, otherwise, we'll use the
193
- # default external encoding.
194
- if source.sub!(/\A#{ENCODING_FLAG}/, '')
195
- encoding = magic_encoding = $1
196
- else
197
- encoding = Encoding.default_external
198
- end
199
-
200
- # Tag the source with the default external encoding
201
- # or the encoding specified in the file
202
- source.force_encoding(encoding)
203
-
204
- # If the user didn't specify an encoding, and the handler
205
- # handles encodings, we simply pass the String as is to
206
- # the handler (with the default_external tag)
207
- if !magic_encoding && @handler.respond_to?(:handles_encoding?) && @handler.handles_encoding?
208
- source
209
- # Otherwise, if the String is valid in the encoding,
210
- # encode immediately to default_internal. This means
211
- # that if a handler doesn't handle encodings, it will
212
- # always get Strings in the default_internal
213
- elsif source.valid_encoding?
214
- source.encode!
215
- # Otherwise, since the String is invalid in the encoding
216
- # specified, raise an exception
217
- else
218
- raise WrongEncodingError.new(source, encoding)
219
- end
220
- end
221
-
222
- protected
223
-
224
- # Compile a template. This method ensures a template is compiled
225
- # just once and removes the source after it is compiled.
226
- def compile!(view) #:nodoc:
227
- return if @compiled
228
-
229
- # Templates can be used concurrently in threaded environments
230
- # so compilation and any instance variable modification must
231
- # be synchronized
232
- @compile_mutex.synchronize do
233
- # Any thread holding this lock will be compiling the template needed
234
- # by the threads waiting. So re-check the @compiled flag to avoid
235
- # re-compilation
236
- return if @compiled
237
-
238
- if view.is_a?(ActionView::CompiledTemplates)
239
- mod = ActionView::CompiledTemplates
240
- else
241
- mod = view.singleton_class
242
- end
243
-
244
- compile(view, mod)
245
-
246
- # Just discard the source if we have a virtual path. This
247
- # means we can get the template back.
248
- @source = nil if @virtual_path
249
- @compiled = true
250
- end
251
- end
252
-
253
- # Among other things, this method is responsible for properly setting
254
- # the encoding of the compiled template.
255
- #
256
- # If the template engine handles encodings, we send the encoded
257
- # String to the engine without further processing. This allows
258
- # the template engine to support additional mechanisms for
259
- # specifying the encoding. For instance, ERB supports <%# encoding: %>
260
- #
261
- # Otherwise, after we figure out the correct encoding, we then
262
- # encode the source into <tt>Encoding.default_internal</tt>.
263
- # In general, this means that templates will be UTF-8 inside of Rails,
264
- # regardless of the original source encoding.
265
- def compile(view, mod) #:nodoc:
266
- encode!
267
- method_name = self.method_name
268
- code = @handler.call(self)
269
-
270
- # Make sure that the resulting String to be evalled is in the
271
- # encoding of the code
272
- source = <<-end_src
273
- def #{method_name}(local_assigns, output_buffer)
274
- _old_virtual_path, @virtual_path = @virtual_path, #{@virtual_path.inspect};_old_output_buffer = @output_buffer;#{locals_code};#{code}
275
- ensure
276
- @virtual_path, @output_buffer = _old_virtual_path, _old_output_buffer
277
- end
278
- end_src
279
-
280
- if source.encoding_aware?
281
- # Make sure the source is in the encoding of the returned code
282
- source.force_encoding(code.encoding)
283
-
284
- # In case we get back a String from a handler that is not in
285
- # BINARY or the default_internal, encode it to the default_internal
286
- source.encode!
287
-
288
- # Now, validate that the source we got back from the template
289
- # handler is valid in the default_internal. This is for handlers
290
- # that handle encoding but screw up
291
- unless source.valid_encoding?
292
- raise WrongEncodingError.new(@source, Encoding.default_internal)
293
- end
294
- end
295
-
296
- begin
297
- mod.module_eval(source, identifier, 0)
298
- ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
299
- rescue Exception => e # errors from template code
300
- if logger = (view && view.logger)
301
- logger.debug "ERROR: compiling #{method_name} RAISED #{e}"
302
- logger.debug "Function body: #{source}"
303
- logger.debug "Backtrace: #{e.backtrace.join("\n")}"
304
- end
305
-
306
- raise ActionView::Template::Error.new(self, {}, e)
307
- end
308
- end
309
-
310
- def handle_render_error(view, e) #:nodoc:
311
- if e.is_a?(Template::Error)
312
- e.sub_template_of(self)
313
- raise e
314
- else
315
- assigns = view.respond_to?(:assigns) ? view.assigns : {}
316
- template = self
317
- unless template.source
318
- template = refresh(view)
319
- template.encode!
320
- end
321
- raise Template::Error.new(template, assigns, e)
322
- end
323
- end
324
-
325
- def locals_code #:nodoc:
326
- @locals.map { |key| "#{key} = local_assigns[:#{key}];" }.join
327
- end
328
-
329
- def method_name #:nodoc:
330
- @method_name ||= "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}".gsub('-', "_")
331
- end
332
-
333
- def identifier_method_name #:nodoc:
334
- inspect.gsub(/[^a-z_]/, '_')
335
- end
336
- end
337
- end
@@ -1,245 +0,0 @@
1
- require 'active_support/core_ext/object/blank'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'active_support/core_ext/module/remove_method'
4
- require 'action_controller'
5
- require 'action_controller/test_case'
6
- require 'action_view'
7
-
8
- module ActionView
9
- # = Action View Test Case
10
- class TestCase < ActiveSupport::TestCase
11
- class TestController < ActionController::Base
12
- include ActionDispatch::TestProcess
13
-
14
- attr_accessor :request, :response, :params
15
-
16
- class << self
17
- attr_writer :controller_path
18
- end
19
-
20
- def controller_path=(path)
21
- self.class.controller_path=(path)
22
- end
23
-
24
- def initialize
25
- super
26
- self.class.controller_path = ""
27
- @request = ActionController::TestRequest.new
28
- @response = ActionController::TestResponse.new
29
-
30
- @request.env.delete('PATH_INFO')
31
- @params = {}
32
- end
33
- end
34
-
35
- module Behavior
36
- extend ActiveSupport::Concern
37
-
38
- include ActionDispatch::Assertions, ActionDispatch::TestProcess
39
- include ActionController::TemplateAssertions
40
- include ActionView::Context
41
-
42
- include ActionDispatch::Routing::PolymorphicRoutes
43
- include ActionController::RecordIdentifier
44
-
45
- include AbstractController::Helpers
46
- include ActionView::Helpers
47
-
48
- delegate :lookup_context, :to => :controller
49
- attr_accessor :controller, :output_buffer, :rendered
50
-
51
- module ClassMethods
52
- def tests(helper_class)
53
- case helper_class
54
- when String, Symbol
55
- self.helper_class = "#{helper_class.to_s.underscore}_helper".camelize.safe_constantize
56
- when Module
57
- self.helper_class = helper_class
58
- end
59
- end
60
-
61
- def determine_default_helper_class(name)
62
- mod = name.sub(/Test$/, '').constantize
63
- mod.is_a?(Class) ? nil : mod
64
- rescue NameError
65
- nil
66
- end
67
-
68
- def helper_method(*methods)
69
- # Almost a duplicate from ActionController::Helpers
70
- methods.flatten.each do |method|
71
- _helpers.module_eval <<-end_eval
72
- def #{method}(*args, &block) # def current_user(*args, &block)
73
- _test_case.send(%(#{method}), *args, &block) # _test_case.send(%(current_user), *args, &block)
74
- end # end
75
- end_eval
76
- end
77
- end
78
-
79
- attr_writer :helper_class
80
-
81
- def helper_class
82
- @helper_class ||= determine_default_helper_class(name)
83
- end
84
-
85
- def new(*)
86
- include_helper_modules!
87
- super
88
- end
89
-
90
- private
91
-
92
- def include_helper_modules!
93
- helper(helper_class) if helper_class
94
- include _helpers
95
- end
96
-
97
- end
98
-
99
- def setup_with_controller
100
- @controller = ActionView::TestCase::TestController.new
101
- @request = @controller.request
102
- @output_buffer = ActiveSupport::SafeBuffer.new
103
- @rendered = ''
104
-
105
- make_test_case_available_to_view!
106
- say_no_to_protect_against_forgery!
107
- end
108
-
109
- def config
110
- @controller.config if @controller.respond_to?(:config)
111
- end
112
-
113
- def render(options = {}, local_assigns = {}, &block)
114
- view.assign(view_assigns)
115
- @rendered << output = view.render(options, local_assigns, &block)
116
- output
117
- end
118
-
119
- def locals
120
- @locals ||= {}
121
- end
122
-
123
- included do
124
- setup :setup_with_controller
125
- end
126
-
127
- private
128
-
129
- # Support the selector assertions
130
- #
131
- # Need to experiment if this priority is the best one: rendered => output_buffer
132
- def response_from_page
133
- HTML::Document.new(@rendered.blank? ? @output_buffer : @rendered).root
134
- end
135
-
136
- def say_no_to_protect_against_forgery!
137
- _helpers.module_eval do
138
- remove_possible_method :protect_against_forgery?
139
- def protect_against_forgery?
140
- false
141
- end
142
- end
143
- end
144
-
145
- def make_test_case_available_to_view!
146
- test_case_instance = self
147
- _helpers.module_eval do
148
- unless private_method_defined?(:_test_case)
149
- define_method(:_test_case) { test_case_instance }
150
- private :_test_case
151
- end
152
- end
153
- end
154
-
155
- module Locals
156
- attr_accessor :locals
157
-
158
- def render(options = {}, local_assigns = {})
159
- case options
160
- when Hash
161
- if block_given?
162
- locals[options[:layout]] = options[:locals]
163
- elsif options.key?(:partial)
164
- locals[options[:partial]] = options[:locals]
165
- end
166
- else
167
- locals[options] = local_assigns
168
- end
169
-
170
- super
171
- end
172
- end
173
-
174
- # The instance of ActionView::Base that is used by +render+.
175
- def view
176
- @view ||= begin
177
- view = @controller.view_context
178
- view.singleton_class.send :include, _helpers
179
- view.extend(Locals)
180
- view.locals = self.locals
181
- view.output_buffer = self.output_buffer
182
- view
183
- end
184
- end
185
-
186
- alias_method :_view, :view
187
-
188
- INTERNAL_IVARS = %w{
189
- @__name__
190
- @__io__
191
- @_assertion_wrapped
192
- @_assertions
193
- @_result
194
- @_routes
195
- @controller
196
- @layouts
197
- @locals
198
- @method_name
199
- @output_buffer
200
- @partials
201
- @passed
202
- @rendered
203
- @request
204
- @routes
205
- @templates
206
- @options
207
- @test_passed
208
- @view
209
- @view_context_class
210
- }
211
-
212
- def _user_defined_ivars
213
- instance_variables.map(&:to_s) - INTERNAL_IVARS
214
- end
215
-
216
- # Returns a Hash of instance variables and their values, as defined by
217
- # the user in the test case, which are then assigned to the view being
218
- # rendered. This is generally intended for internal use and extension
219
- # frameworks.
220
- def view_assigns
221
- Hash[_user_defined_ivars.map do |var|
222
- [var[1, var.length].to_sym, instance_variable_get(var)]
223
- end]
224
- end
225
-
226
- def _routes
227
- @controller._routes if @controller.respond_to?(:_routes)
228
- end
229
-
230
- def method_missing(selector, *args)
231
- if @controller.respond_to?(:_routes) &&
232
- ( @controller._routes.named_routes.helpers.include?(selector) ||
233
- @controller._routes.mounted_helpers.method_defined?(selector) )
234
- @controller.__send__(selector, *args)
235
- else
236
- super
237
- end
238
- end
239
-
240
- end
241
-
242
- include Behavior
243
-
244
- end
245
- end
@@ -1,50 +0,0 @@
1
- require 'action_view/template/resolver'
2
-
3
- module ActionView #:nodoc:
4
- # Use FixtureResolver in your tests to simulate the presence of files on the
5
- # file system. This is used internally by Rails' own test suite, and is
6
- # useful for testing extensions that have no way of knowing what the file
7
- # system will look like at runtime.
8
- class FixtureResolver < PathResolver
9
- attr_reader :hash
10
-
11
- def initialize(hash = {}, pattern=nil)
12
- super(pattern)
13
- @hash = hash
14
- end
15
-
16
- def to_s
17
- @hash.keys.join(', ')
18
- end
19
-
20
- private
21
-
22
- def query(path, exts, formats)
23
- query = ""
24
- EXTENSIONS.each do |ext|
25
- query << '(' << exts[ext].map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)'
26
- end
27
- query = /^(#{Regexp.escape(path)})#{query}$/
28
-
29
- templates = []
30
- @hash.each do |_path, array|
31
- source, updated_at = array
32
- next unless _path =~ query
33
- handler, format = extract_handler_and_format(_path, formats)
34
- templates << Template.new(source, _path, handler,
35
- :virtual_path => path.virtual, :format => format, :updated_at => updated_at)
36
- end
37
-
38
- templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
39
- end
40
- end
41
-
42
- class NullResolver < PathResolver
43
- def query(path, exts, formats)
44
- handler, format = extract_handler_and_format(path, formats)
45
- [ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)]
46
- end
47
- end
48
-
49
- end
50
-