actionpack 3.0.1 → 3.0.2

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 (42) hide show
  1. data/CHANGELOG +7 -1
  2. data/lib/abstract_controller/base.rb +1 -0
  3. data/lib/abstract_controller/callbacks.rb +2 -0
  4. data/lib/abstract_controller/rendering.rb +4 -4
  5. data/lib/action_controller/base.rb +2 -0
  6. data/lib/action_controller/metal.rb +8 -3
  7. data/lib/action_controller/metal/head.rb +2 -4
  8. data/lib/action_controller/metal/http_authentication.rb +8 -10
  9. data/lib/action_controller/metal/mime_responds.rb +1 -1
  10. data/lib/action_controller/metal/redirecting.rb +4 -2
  11. data/lib/action_controller/metal/renderers.rb +1 -1
  12. data/lib/action_controller/metal/responder.rb +20 -0
  13. data/lib/action_controller/test_case.rb +7 -0
  14. data/lib/action_controller/vendor/html-scanner/html/node.rb +5 -11
  15. data/lib/action_dispatch/http/request.rb +19 -2
  16. data/lib/action_dispatch/http/response.rb +9 -10
  17. data/lib/action_dispatch/http/upload.rb +21 -29
  18. data/lib/action_dispatch/middleware/cookies.rb +11 -3
  19. data/lib/action_dispatch/railtie.rb +0 -5
  20. data/lib/action_dispatch/routing.rb +75 -22
  21. data/lib/action_dispatch/routing/mapper.rb +429 -60
  22. data/lib/action_dispatch/routing/polymorphic_routes.rb +1 -1
  23. data/lib/action_dispatch/routing/route.rb +2 -1
  24. data/lib/action_dispatch/routing/url_for.rb +4 -5
  25. data/lib/action_dispatch/testing/integration.rb +9 -7
  26. data/lib/action_pack/version.rb +2 -2
  27. data/lib/action_view/base.rb +1 -1
  28. data/lib/action_view/helpers/asset_tag_helper.rb +1 -1
  29. data/lib/action_view/helpers/capture_helper.rb +2 -1
  30. data/lib/action_view/helpers/date_helper.rb +2 -0
  31. data/lib/action_view/helpers/form_helper.rb +15 -12
  32. data/lib/action_view/helpers/form_options_helper.rb +5 -5
  33. data/lib/action_view/helpers/javascript_helper.rb +2 -1
  34. data/lib/action_view/helpers/number_helper.rb +23 -12
  35. data/lib/action_view/helpers/prototype_helper.rb +4 -4
  36. data/lib/action_view/helpers/text_helper.rb +18 -0
  37. data/lib/action_view/helpers/url_helper.rb +12 -10
  38. data/lib/action_view/render/partials.rb +52 -8
  39. data/lib/action_view/render/rendering.rb +1 -1
  40. data/lib/action_view/template/handlers/erb.rb +6 -1
  41. data/lib/action_view/test_case.rb +26 -10
  42. metadata +35 -12
@@ -26,6 +26,36 @@ module ActionView
26
26
  # This would first render "advertiser/_account.erb" with @buyer passed in as the local variable +account+, then
27
27
  # render "advertiser/_ad.erb" and pass the local variable +ad+ to the template for display.
28
28
  #
29
+ # == The :as and :object options
30
+ #
31
+ # By default PartialRenderer uses the template name for the local name of the object passed into the template.
32
+ # These examples are effectively the same:
33
+ #
34
+ # <%= render :partial => "contract", :locals => { :contract => @contract } %>
35
+ #
36
+ # <%= render :partial => "contract" %>
37
+ #
38
+ # By specifying the :as option we can change the way the local variable is namedin the template.
39
+ # These examples are effectively the same:
40
+ #
41
+ # <%= render :partial => "contract", :as => :agreement
42
+ #
43
+ # <%= render :partial => "contract", :locals => { :agreement => @contract }
44
+ #
45
+ # The :object option can be used to directly specify which object is rendered into the partial.
46
+ #
47
+ # Revisiting a previous example we could have written this code.
48
+ #
49
+ # <%= render :partial => "account", :object => @buyer %>
50
+ #
51
+ # <% for ad in @advertisements %>
52
+ # <%= render :partial => "ad", :object => ad %>
53
+ # <% end %>
54
+ #
55
+ # The :object and :as options can be used together. We might have a partial which we have named genericly,
56
+ # such as 'form'. Using :object and :as together helps us.
57
+ #
58
+ # <%= render :partial => "form", :object => @contract, :as => :contract %>
29
59
  # == Rendering a collection of partials
30
60
  #
31
61
  # The example of partial use describes a familiar pattern where a template needs to iterate over an array and
@@ -39,6 +69,13 @@ module ActionView
39
69
  # iteration counter will automatically be made available to the template with a name of the form
40
70
  # +partial_name_counter+. In the case of the example above, the template would be fed +ad_counter+.
41
71
  #
72
+ # The :as option may be used when rendering partials.
73
+ #
74
+ # Also, you can specify a partial which will be render as a spacer between each element by passing partial name to
75
+ # +:spacer_template+. The following example will render "advertiser/_ad_divider.erb" between each ad partial.
76
+ #
77
+ # <%= render :partial => "ad", :collection => @advertisements, :spacer_template => "ad_divider" %>
78
+ #
42
79
  # NOTE: Due to backwards compatibility concerns, the collection can't be one of hashes. Normally you'd also
43
80
  # just keep domain objects, like Active Records, in there.
44
81
  #
@@ -200,7 +237,7 @@ module ActionView
200
237
  else
201
238
  @object = partial
202
239
 
203
- if @collection = collection
240
+ if @collection = collection_from_object || collection
204
241
  paths = @collection_paths = @collection.map { |o| partial_path(o) }
205
242
  @path = paths.uniq.size == 1 ? paths.first : nil
206
243
  else
@@ -218,13 +255,15 @@ module ActionView
218
255
  render_collection
219
256
  end
220
257
  else
258
+ block, options, locals = @block, @options, @locals
259
+
221
260
  content = ActiveSupport::Notifications.instrument("render_partial.action_view",
222
261
  :identifier => identifier) do
223
262
  render_partial
224
263
  end
225
264
 
226
- if !@block && (layout = @options[:layout])
227
- content = @view._render_layout(find_template(layout), @locals){ content }
265
+ if !block && (layout = options[:layout])
266
+ content = @view._render_layout(find_template(layout), locals){ content }
228
267
  end
229
268
 
230
269
  content
@@ -286,23 +325,28 @@ module ActionView
286
325
  end
287
326
 
288
327
  def render_partial(object = @object)
289
- locals, view, template = @locals, @view, @template
328
+ locals, view, template, block = @locals, @view, @template, @block
290
329
 
291
330
  object ||= locals[template.variable_name]
292
331
  locals[@options[:as] || template.variable_name] = object
293
332
 
294
333
  template.render(view, locals) do |*name|
295
- view._layout_for(*name, &@block)
334
+ view._layout_for(*name, &block)
296
335
  end
297
336
  end
298
337
 
299
338
  private
300
339
 
301
340
  def collection
341
+ if @options.key?(:collection)
342
+ collection = @options[:collection]
343
+ collection.respond_to?(:to_ary) ? collection.to_ary : []
344
+ end
345
+ end
346
+
347
+ def collection_from_object
302
348
  if @object.respond_to?(:to_ary)
303
- @object
304
- elsif @options.key?(:collection)
305
- @options[:collection] || []
349
+ @object.to_ary
306
350
  end
307
351
  end
308
352
 
@@ -17,7 +17,7 @@ module ActionView
17
17
  case options
18
18
  when Hash
19
19
  if block_given?
20
- _render_partial(options.merge(:partial => options[:layout]), &block)
20
+ _render_partial(options.merge(:partial => options.delete(:layout)), &block)
21
21
  elsif options.key?(:partial)
22
22
  _render_partial(options)
23
23
  else
@@ -14,6 +14,7 @@ module ActionView
14
14
  super(value.to_s)
15
15
  end
16
16
  alias :append= :<<
17
+ alias :safe_append= :safe_concat
17
18
 
18
19
  def append_if_string=(value)
19
20
  if value.is_a?(String) && !value.is_a?(NonConcattingString)
@@ -54,7 +55,11 @@ module ActionView
54
55
  end
55
56
 
56
57
  def add_expr_escaped(src, code)
57
- src << '@output_buffer.append= ' << escaped_expr(code) << ';'
58
+ if code =~ BLOCK_EXPR
59
+ src << "@output_buffer.safe_append= " << code
60
+ else
61
+ src << "@output_buffer.safe_concat((" << code << ").to_s);"
62
+ end
58
63
  end
59
64
 
60
65
  def add_postamble(src)
@@ -74,6 +74,11 @@ module ActionView
74
74
  @helper_class ||= determine_default_helper_class(name)
75
75
  end
76
76
 
77
+ def new(*)
78
+ include_helper_modules!
79
+ super
80
+ end
81
+
77
82
  private
78
83
 
79
84
  def include_helper_modules!
@@ -89,7 +94,6 @@ module ActionView
89
94
  @output_buffer = ActiveSupport::SafeBuffer.new
90
95
  @rendered = ''
91
96
 
92
- self.class.send(:include_helper_modules!)
93
97
  make_test_case_available_to_view!
94
98
  say_no_to_protect_against_forgery!
95
99
  end
@@ -99,7 +103,7 @@ module ActionView
99
103
  end
100
104
 
101
105
  def render(options = {}, local_assigns = {}, &block)
102
- view.assign(_assigns)
106
+ view.assign(view_assigns)
103
107
  @rendered << output = view.render(options, local_assigns, &block)
104
108
  output
105
109
  end
@@ -162,15 +166,19 @@ module ActionView
162
166
 
163
167
  alias_method :_view, :view
164
168
 
165
- EXCLUDE_IVARS = %w{
169
+ INTERNAL_IVARS = %w{
170
+ @__name__
166
171
  @_assertion_wrapped
172
+ @_assertions
167
173
  @_result
174
+ @_routes
168
175
  @controller
169
176
  @layouts
170
177
  @locals
171
178
  @method_name
172
179
  @output_buffer
173
180
  @partials
181
+ @passed
174
182
  @rendered
175
183
  @request
176
184
  @routes
@@ -180,16 +188,24 @@ module ActionView
180
188
  @view_context_class
181
189
  }
182
190
 
183
- def _instance_variables
184
- instance_variables.map(&:to_s) - EXCLUDE_IVARS
191
+ def _user_defined_ivars
192
+ instance_variables.map(&:to_s) - INTERNAL_IVARS
193
+ end
194
+
195
+ # Returns a Hash of instance variables and their values, as defined by
196
+ # the user in the test case, which are then assigned to the view being
197
+ # rendered. This is generally intended for internal use and extension
198
+ # frameworks.
199
+ def view_assigns
200
+ Hash[_user_defined_ivars.map do |var|
201
+ [var[1..-1].to_sym, instance_variable_get(var)]
202
+ end]
185
203
  end
186
204
 
187
205
  def _assigns
188
- _instance_variables.inject({}) do |hash, var|
189
- name = var[1..-1].to_sym
190
- hash[name] = instance_variable_get(var)
191
- hash
192
- end
206
+ ActiveSupport::Deprecation.warn "ActionView::TestCase#_assigns is deprecated and will be removed in future versions. " <<
207
+ "Please use view_assigns instead."
208
+ view_assigns
193
209
  end
194
210
 
195
211
  def _routes
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 3
7
8
  - 0
8
- - 1
9
- version: 3.0.1
9
+ - 2
10
+ version: 3.0.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Heinemeier Hansson
@@ -14,44 +15,50 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-15 00:00:00 +13:00
18
+ date: 2010-11-15 00:00:00 -06:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activesupport
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - "="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 3
29
32
  - 0
30
- - 1
31
- version: 3.0.1
33
+ - 2
34
+ version: 3.0.2
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: activemodel
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - "="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 3
41
46
  segments:
42
47
  - 3
43
48
  - 0
44
- - 1
45
- version: 3.0.1
49
+ - 2
50
+ version: 3.0.2
46
51
  type: :runtime
47
52
  version_requirements: *id002
48
53
  - !ruby/object:Gem::Dependency
49
54
  name: builder
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ~>
54
60
  - !ruby/object:Gem::Version
61
+ hash: 15
55
62
  segments:
56
63
  - 2
57
64
  - 1
@@ -63,9 +70,11 @@ dependencies:
63
70
  name: i18n
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ~>
68
76
  - !ruby/object:Gem::Version
77
+ hash: 13
69
78
  segments:
70
79
  - 0
71
80
  - 4
@@ -77,9 +86,11 @@ dependencies:
77
86
  name: rack
78
87
  prerelease: false
79
88
  requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
80
90
  requirements:
81
91
  - - ~>
82
92
  - !ruby/object:Gem::Version
93
+ hash: 29
83
94
  segments:
84
95
  - 1
85
96
  - 2
@@ -91,37 +102,43 @@ dependencies:
91
102
  name: rack-test
92
103
  prerelease: false
93
104
  requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
94
106
  requirements:
95
107
  - - ~>
96
108
  - !ruby/object:Gem::Version
109
+ hash: 7
97
110
  segments:
98
111
  - 0
99
112
  - 5
100
- - 4
101
- version: 0.5.4
113
+ - 6
114
+ version: 0.5.6
102
115
  type: :runtime
103
116
  version_requirements: *id006
104
117
  - !ruby/object:Gem::Dependency
105
118
  name: rack-mount
106
119
  prerelease: false
107
120
  requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
108
122
  requirements:
109
123
  - - ~>
110
124
  - !ruby/object:Gem::Version
125
+ hash: 29
111
126
  segments:
112
127
  - 0
113
128
  - 6
114
- - 12
115
- version: 0.6.12
129
+ - 13
130
+ version: 0.6.13
116
131
  type: :runtime
117
132
  version_requirements: *id007
118
133
  - !ruby/object:Gem::Dependency
119
134
  name: tzinfo
120
135
  prerelease: false
121
136
  requirement: &id008 !ruby/object:Gem::Requirement
137
+ none: false
122
138
  requirements:
123
139
  - - ~>
124
140
  - !ruby/object:Gem::Version
141
+ hash: 61
125
142
  segments:
126
143
  - 0
127
144
  - 3
@@ -133,9 +150,11 @@ dependencies:
133
150
  name: erubis
134
151
  prerelease: false
135
152
  requirement: &id009 !ruby/object:Gem::Requirement
153
+ none: false
136
154
  requirements:
137
155
  - - ~>
138
156
  - !ruby/object:Gem::Version
157
+ hash: 27
139
158
  segments:
140
159
  - 2
141
160
  - 6
@@ -326,25 +345,29 @@ rdoc_options: []
326
345
  require_paths:
327
346
  - lib
328
347
  required_ruby_version: !ruby/object:Gem::Requirement
348
+ none: false
329
349
  requirements:
330
350
  - - ">="
331
351
  - !ruby/object:Gem::Version
352
+ hash: 57
332
353
  segments:
333
354
  - 1
334
355
  - 8
335
356
  - 7
336
357
  version: 1.8.7
337
358
  required_rubygems_version: !ruby/object:Gem::Requirement
359
+ none: false
338
360
  requirements:
339
361
  - - ">="
340
362
  - !ruby/object:Gem::Version
363
+ hash: 3
341
364
  segments:
342
365
  - 0
343
366
  version: "0"
344
367
  requirements:
345
368
  - none
346
369
  rubyforge_project: actionpack
347
- rubygems_version: 1.3.6
370
+ rubygems_version: 1.3.7
348
371
  signing_key:
349
372
  specification_version: 3
350
373
  summary: Web-flow and rendering framework putting the VC in MVC (part of Rails).