actionpack 1.9.1 → 1.10.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 (123) hide show
  1. data/CHANGELOG +237 -0
  2. data/README +12 -12
  3. data/lib/action_controller.rb +17 -12
  4. data/lib/action_controller/assertions.rb +119 -67
  5. data/lib/action_controller/base.rb +184 -102
  6. data/lib/action_controller/benchmarking.rb +35 -6
  7. data/lib/action_controller/caching.rb +115 -58
  8. data/lib/action_controller/cgi_ext/cgi_methods.rb +54 -21
  9. data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +39 -35
  10. data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +34 -21
  11. data/lib/action_controller/cgi_process.rb +23 -20
  12. data/lib/action_controller/components.rb +11 -2
  13. data/lib/action_controller/dependencies.rb +0 -5
  14. data/lib/action_controller/deprecated_redirects.rb +17 -0
  15. data/lib/action_controller/filters.rb +13 -9
  16. data/lib/action_controller/flash.rb +7 -7
  17. data/lib/action_controller/helpers.rb +1 -14
  18. data/lib/action_controller/layout.rb +40 -29
  19. data/lib/action_controller/macros/auto_complete.rb +52 -0
  20. data/lib/action_controller/macros/in_place_editing.rb +32 -0
  21. data/lib/action_controller/pagination.rb +44 -28
  22. data/lib/action_controller/request.rb +54 -40
  23. data/lib/action_controller/rescue.rb +8 -6
  24. data/lib/action_controller/routing.rb +77 -28
  25. data/lib/action_controller/scaffolding.rb +10 -14
  26. data/lib/action_controller/session/active_record_store.rb +36 -7
  27. data/lib/action_controller/session_management.rb +126 -0
  28. data/lib/action_controller/streaming.rb +14 -5
  29. data/lib/action_controller/templates/rescues/_request_and_response.rhtml +1 -1
  30. data/lib/action_controller/templates/rescues/_trace.rhtml +24 -0
  31. data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -13
  32. data/lib/action_controller/templates/rescues/template_error.rhtml +4 -2
  33. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  34. data/lib/action_controller/test_process.rb +35 -17
  35. data/lib/action_controller/upload_progress.rb +52 -0
  36. data/lib/action_controller/url_rewriter.rb +21 -16
  37. data/lib/action_controller/vendor/html-scanner/html/document.rb +2 -2
  38. data/lib/action_controller/vendor/html-scanner/html/node.rb +30 -3
  39. data/lib/action_pack/version.rb +9 -0
  40. data/lib/action_view.rb +1 -1
  41. data/lib/action_view/base.rb +204 -60
  42. data/lib/action_view/compiled_templates.rb +70 -0
  43. data/lib/action_view/helpers/active_record_helper.rb +7 -3
  44. data/lib/action_view/helpers/asset_tag_helper.rb +22 -12
  45. data/lib/action_view/helpers/capture_helper.rb +2 -10
  46. data/lib/action_view/helpers/date_helper.rb +21 -13
  47. data/lib/action_view/helpers/form_helper.rb +14 -10
  48. data/lib/action_view/helpers/form_options_helper.rb +4 -4
  49. data/lib/action_view/helpers/form_tag_helper.rb +59 -25
  50. data/lib/action_view/helpers/java_script_macros_helper.rb +188 -0
  51. data/lib/action_view/helpers/javascript_helper.rb +68 -133
  52. data/lib/action_view/helpers/javascripts/controls.js +427 -165
  53. data/lib/action_view/helpers/javascripts/dragdrop.js +256 -277
  54. data/lib/action_view/helpers/javascripts/effects.js +766 -277
  55. data/lib/action_view/helpers/javascripts/prototype.js +906 -218
  56. data/lib/action_view/helpers/javascripts/slider.js +258 -0
  57. data/lib/action_view/helpers/number_helper.rb +4 -3
  58. data/lib/action_view/helpers/pagination_helper.rb +42 -27
  59. data/lib/action_view/helpers/tag_helper.rb +25 -11
  60. data/lib/action_view/helpers/text_helper.rb +119 -13
  61. data/lib/action_view/helpers/upload_progress_helper.rb +2 -2
  62. data/lib/action_view/helpers/url_helper.rb +68 -21
  63. data/lib/action_view/partials.rb +17 -6
  64. data/lib/action_view/template_error.rb +19 -24
  65. data/rakefile +4 -3
  66. data/test/abstract_unit.rb +2 -1
  67. data/test/controller/action_pack_assertions_test.rb +62 -2
  68. data/test/controller/active_record_assertions_test.rb +5 -6
  69. data/test/controller/active_record_store_test.rb +23 -1
  70. data/test/controller/addresses_render_test.rb +4 -0
  71. data/test/controller/{base_tests.rb → base_test.rb} +4 -3
  72. data/test/controller/benchmark_test.rb +36 -0
  73. data/test/controller/caching_filestore.rb +22 -40
  74. data/test/controller/capture_test.rb +10 -1
  75. data/test/controller/cgi_test.rb +145 -23
  76. data/test/controller/components_test.rb +50 -0
  77. data/test/controller/custom_handler_test.rb +3 -3
  78. data/test/controller/fake_controllers.rb +24 -0
  79. data/test/controller/filters_test.rb +6 -6
  80. data/test/controller/flash_test.rb +6 -6
  81. data/test/controller/fragment_store_setting_test.rb +45 -0
  82. data/test/controller/helper_test.rb +1 -3
  83. data/test/controller/new_render_test.rb +119 -7
  84. data/test/controller/redirect_test.rb +11 -1
  85. data/test/controller/render_test.rb +34 -1
  86. data/test/controller/request_test.rb +14 -5
  87. data/test/controller/routing_test.rb +238 -42
  88. data/test/controller/send_file_test.rb +11 -10
  89. data/test/controller/session_management_test.rb +94 -0
  90. data/test/controller/test_test.rb +194 -5
  91. data/test/controller/url_rewriter_test.rb +46 -0
  92. data/test/fixtures/layouts/talk_from_action.rhtml +2 -0
  93. data/test/fixtures/layouts/yield.rhtml +2 -0
  94. data/test/fixtures/multipart/binary_file +0 -0
  95. data/test/fixtures/multipart/large_text_file +10 -0
  96. data/test/fixtures/multipart/mixed_files +0 -0
  97. data/test/fixtures/multipart/single_parameter +5 -0
  98. data/test/fixtures/multipart/text_file +10 -0
  99. data/test/fixtures/test/_customer_greeting.rhtml +1 -0
  100. data/test/fixtures/test/_hash_object.rhtml +1 -0
  101. data/test/fixtures/test/_person.rhtml +2 -0
  102. data/test/fixtures/test/action_talk_to_layout.rhtml +2 -0
  103. data/test/fixtures/test/content_for.rhtml +2 -0
  104. data/test/fixtures/test/potential_conflicts.rhtml +4 -0
  105. data/test/template/active_record_helper_test.rb +15 -8
  106. data/test/template/asset_tag_helper_test.rb +40 -16
  107. data/test/template/compiled_templates_tests.rb +63 -0
  108. data/test/template/date_helper_test.rb +80 -4
  109. data/test/template/form_helper_test.rb +48 -42
  110. data/test/template/form_options_helper_test.rb +40 -40
  111. data/test/template/form_tag_helper_test.rb +21 -15
  112. data/test/template/java_script_macros_helper_test.rb +56 -0
  113. data/test/template/javascript_helper_test.rb +70 -47
  114. data/test/template/number_helper_test.rb +2 -0
  115. data/test/template/tag_helper_test.rb +9 -0
  116. data/test/template/text_helper_test.rb +146 -1
  117. data/test/template/upload_progress_helper_testx.rb +11 -147
  118. data/test/template/url_helper_test.rb +90 -22
  119. data/test/testing_sandbox.rb +26 -0
  120. metadata +37 -7
  121. data/lib/action_controller/auto_complete.rb +0 -47
  122. data/lib/action_controller/deprecated_renders_and_redirects.rb +0 -76
  123. data/lib/action_controller/session.rb +0 -14
@@ -25,6 +25,22 @@ class CallerController < ActionController::Base
25
25
  render_text "Yes, ma'am"
26
26
  end
27
27
 
28
+ def set_flash
29
+ render_component(:controller => "callee", :action => "set_flash")
30
+ end
31
+
32
+ def use_flash
33
+ render_component(:controller => "callee", :action => "use_flash")
34
+ end
35
+
36
+ def calling_redirected
37
+ render_component(:controller => "callee", :action => "redirected")
38
+ end
39
+
40
+ def calling_redirected_as_string
41
+ render_template "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
42
+ end
43
+
28
44
  def rescue_action(e) raise end
29
45
  end
30
46
 
@@ -36,6 +52,19 @@ class CalleeController < ActionController::Base
36
52
  def blowing_up
37
53
  render_text "It's game over, man, just game over, man!", "500 Internal Server Error"
38
54
  end
55
+
56
+ def set_flash
57
+ flash[:notice] = 'My stoney baby'
58
+ render :text => 'flash is set'
59
+ end
60
+
61
+ def use_flash
62
+ render :text => flash[:notice] || 'no flash'
63
+ end
64
+
65
+ def redirected
66
+ redirect_to :controller => "callee", :action => "being_called"
67
+ end
39
68
 
40
69
  def rescue_action(e) raise end
41
70
  end
@@ -71,4 +100,25 @@ class ComponentsTest < Test::Unit::TestCase
71
100
  get :internal_caller
72
101
  assert_equal "Are you there? Yes, ma'am", @response.body
73
102
  end
103
+
104
+ def test_flash
105
+ get :set_flash
106
+ assert_equal 'My stoney baby', flash[:notice]
107
+ get :use_flash
108
+ assert_equal 'My stoney baby', @response.body
109
+ get :use_flash
110
+ assert_equal 'no flash', @response.body
111
+ end
112
+
113
+ def test_component_redirect_redirects
114
+ get :calling_redirected
115
+
116
+ assert_redirected_to :action => "being_called"
117
+ end
118
+
119
+ def test_component_as_string_redirect_renders_redirecte_action
120
+ get :calling_redirected_as_string
121
+
122
+ assert_equal "Lady of the House, speaking", @response.body
123
+ end
74
124
  end
@@ -19,15 +19,15 @@ class CustomHandlerTest < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_custom_render
22
- result = @view.render_template( "foo", "hello <%= one %>", "one" => "two" )
22
+ result = @view.render_template( "foo", "hello <%= one %>", nil, :one => "two" )
23
23
  assert_equal(
24
- [ "hello <%= one %>", { "one" => "two" }, @view ],
24
+ [ "hello <%= one %>", { :one => "two" }, @view ],
25
25
  result )
26
26
  end
27
27
 
28
28
  def test_unhandled_extension
29
29
  # uses the ERb handler by default if the extension isn't recognized
30
- result = @view.render_template( "bar", "hello <%= one %>", "one" => "two" )
30
+ result = @view.render_template( "bar", "hello <%= one %>", nil, :one => "two" )
31
31
  assert_equal "hello two", result
32
32
  end
33
33
  end
@@ -0,0 +1,24 @@
1
+ module Object::Controllers
2
+ def self.const_available?(*args)
3
+ const_defined?(*args)
4
+ end
5
+
6
+ class ContentController < ActionController::Base
7
+ end
8
+
9
+ module Admin
10
+ def self.const_available?(*args)
11
+ const_defined?(*args)
12
+ end
13
+
14
+ class UserController < ActionController::Base
15
+ end
16
+ class NewsFeedController < ActionController::Base
17
+ end
18
+ end
19
+ end
20
+
21
+ ActionController::Routing::Routes.draw do |map|
22
+ map.route_one 'route_one', :controller => 'elsewhere', :action => 'flash_me'
23
+ map.connect ':controller/:action/:id'
24
+ end
@@ -5,7 +5,7 @@ class FilterTest < Test::Unit::TestCase
5
5
  before_filter :ensure_login
6
6
 
7
7
  def show
8
- render_text "ran action"
8
+ render :inline => "ran action"
9
9
  end
10
10
 
11
11
  private
@@ -20,26 +20,26 @@ class FilterTest < Test::Unit::TestCase
20
20
 
21
21
  def show
22
22
  @ran_action = true
23
- render_text "ran action"
23
+ render :inline => "ran action"
24
24
  end
25
25
 
26
26
  private
27
27
  def render_something_else
28
- render_text "something else"
28
+ render :inline => "something else"
29
29
  end
30
30
  end
31
31
 
32
32
  class ConditionalFilterController < ActionController::Base
33
33
  def show
34
- render_text "ran action"
34
+ render :inline => "ran action"
35
35
  end
36
36
 
37
37
  def another_action
38
- render_text "ran action"
38
+ render :inline => "ran action"
39
39
  end
40
40
 
41
41
  def show_without_filter
42
- render_text "ran action without filter"
42
+ render :inline => "ran action without filter"
43
43
  end
44
44
 
45
45
  private
@@ -4,32 +4,32 @@ class FlashTest < Test::Unit::TestCase
4
4
  class TestController < ActionController::Base
5
5
  def set_flash
6
6
  flash["that"] = "hello"
7
- render_text "hello"
7
+ render :inline => "hello"
8
8
  end
9
9
 
10
10
  def set_flash_now
11
11
  flash.now["that"] = "hello"
12
12
  @flash_copy = {}.update flash
13
- render_text "hello"
13
+ render :inline => "hello"
14
14
  end
15
15
 
16
16
  def attempt_to_use_flash_now
17
17
  @flash_copy = {}.update flash
18
18
  @flashy = flash["that"]
19
- render_text "hello"
19
+ render :inline => "hello"
20
20
  end
21
21
 
22
22
  def use_flash
23
23
  @flash_copy = {}.update flash
24
24
  @flashy = flash["that"]
25
- render_text "hello"
25
+ render :inline => "hello"
26
26
  end
27
27
 
28
28
  def use_flash_and_keep_it
29
29
  @flash_copy = {}.update flash
30
30
  @flashy = flash["that"]
31
31
  keep_flash
32
- render_text "hello"
32
+ render :inline => "hello"
33
33
  end
34
34
 
35
35
  def rescue_action(e)
@@ -91,4 +91,4 @@ class FlashTest < Test::Unit::TestCase
91
91
  def process_request
92
92
  TestController.process(@request, @response)
93
93
  end
94
- end
94
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
2
+
3
+ MemCache = Struct.new(:MemCache, :address) unless Object.const_defined?(:MemCache)
4
+
5
+ class FragmentCacheStoreSettingTest < Test::Unit::TestCase
6
+ def teardown
7
+ ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::MemoryStore.new
8
+ end
9
+
10
+ def test_file_fragment_cache_store
11
+ ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory"
12
+ assert_kind_of(
13
+ ActionController::Caching::Fragments::FileStore,
14
+ ActionController::Base.fragment_cache_store
15
+ )
16
+ assert_equal "/path/to/cache/directory", ActionController::Base.fragment_cache_store.cache_path
17
+ end
18
+
19
+ def test_drb_fragment_cache_store
20
+ ActionController::Base.fragment_cache_store = :drb_store, "druby://localhost:9192"
21
+ assert_kind_of(
22
+ ActionController::Caching::Fragments::DRbStore,
23
+ ActionController::Base.fragment_cache_store
24
+ )
25
+ assert_equal "druby://localhost:9192", ActionController::Base.fragment_cache_store.address
26
+ end
27
+
28
+ def test_mem_cache_fragment_cache_store
29
+ ActionController::Base.fragment_cache_store = :mem_cache_store, "localhost"
30
+ assert_kind_of(
31
+ ActionController::Caching::Fragments::MemCacheStore,
32
+ ActionController::Base.fragment_cache_store
33
+ )
34
+ assert_equal "localhost", ActionController::Base.fragment_cache_store.address
35
+ end
36
+
37
+ def test_object_assigned_fragment_cache_store
38
+ ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new("/path/to/cache/directory")
39
+ assert_kind_of(
40
+ ActionController::Caching::Fragments::FileStore,
41
+ ActionController::Base.fragment_cache_store
42
+ )
43
+ assert_equal "/path/to/cache/directory", ActionController::Base.fragment_cache_store.cache_path
44
+ end
45
+ end
@@ -121,9 +121,7 @@ class HelperTest < Test::Unit::TestCase
121
121
  end
122
122
 
123
123
  def test_helper=(helper_module)
124
- old_verbose, $VERBOSE = $VERBOSE, nil
125
- self.class.const_set('TestHelper', helper_module)
126
- $VERBOSE = old_verbose
124
+ silence_warnings { self.class.const_set('TestHelper', helper_module) }
127
125
  end
128
126
  end
129
127
 
@@ -59,6 +59,10 @@ class NewRenderTestController < ActionController::Base
59
59
  def rendering_without_layout
60
60
  render :action => "hello_world", :layout => false
61
61
  end
62
+
63
+ def layout_overriding_layout
64
+ render :action => "hello_world", :layout => "standard"
65
+ end
62
66
 
63
67
  def rendering_nothing_on_layout
64
68
  render :nothing => true
@@ -81,7 +85,32 @@ class NewRenderTestController < ActionController::Base
81
85
  def partial_only_with_layout
82
86
  render :partial => "partial_only", :layout => true
83
87
  end
88
+
89
+ def partial_with_locals
90
+ render :partial => "customer", :locals => { :customer => Customer.new("david") }
91
+ end
92
+
93
+ def partial_collection
94
+ render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
95
+ end
96
+
97
+ def partial_collection_with_locals
98
+ render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
99
+ end
100
+
101
+ def empty_partial_collection
102
+ render :partial => "customer", :collection => []
103
+ end
104
+
105
+ def partial_with_hash_object
106
+ render :partial => "hash_object", :object => {:first_name => "Sam"}
107
+ end
84
108
 
109
+ def partial_with_implicit_local_assignment
110
+ @customer = Customer.new("Marcel")
111
+ render :partial => "customer"
112
+ end
113
+
85
114
  def hello_in_a_string
86
115
  @customers = [ Customer.new("david"), Customer.new("mary") ]
87
116
  render :text => "How's there? #{render_to_string("test/list")}"
@@ -92,7 +121,7 @@ class NewRenderTestController < ActionController::Base
92
121
  end
93
122
 
94
123
  def accessing_params_in_template_with_layout
95
- render :inline => "Hello: <%= params[:name] %>", :layout => nil
124
+ render :layout => nil, :inline => "Hello: <%= params[:name] %>"
96
125
  end
97
126
 
98
127
  def render_with_explicit_template
@@ -114,6 +143,25 @@ class NewRenderTestController < ActionController::Base
114
143
  redirect_to :action => "double_render"
115
144
  end
116
145
 
146
+ def rendering_with_conflicting_local_vars
147
+ @name = "David"
148
+ def @template.name() nil end
149
+ render :action => "potential_conflicts"
150
+ end
151
+
152
+ def action_talk_to_layout
153
+ # Action template sets variable that's picked up by layout
154
+ end
155
+
156
+ def render_text_with_assigns
157
+ @hello = "world"
158
+ render :text => "foo"
159
+ end
160
+
161
+ def yield_content_for
162
+ render :action => "content_for", :layout => "yield"
163
+ end
164
+
117
165
  def rescue_action(e) raise end
118
166
 
119
167
  private
@@ -128,6 +176,8 @@ class NewRenderTestController < ActionController::Base
128
176
  "layouts/standard"
129
177
  when "builder_layout_test"
130
178
  "layouts/builder"
179
+ when "action_talk_to_layout", "layout_overriding_layout"
180
+ "layouts/talk_from_action"
131
181
  end
132
182
  end
133
183
  end
@@ -190,15 +240,22 @@ class NewRenderTest < Test::Unit::TestCase
190
240
  end
191
241
 
192
242
  def test_access_to_request_in_view
243
+ view_internals_old_value = ActionController::Base.view_controller_internals
244
+
193
245
  ActionController::Base.view_controller_internals = false
246
+ ActionController::Base.protected_variables_cache = nil
194
247
 
195
248
  get :hello_world
196
249
  assert_nil(assigns["request"])
197
250
 
198
251
  ActionController::Base.view_controller_internals = true
252
+ ActionController::Base.protected_variables_cache = nil
199
253
 
200
254
  get :hello_world
201
255
  assert_kind_of ActionController::AbstractRequest, assigns["request"]
256
+
257
+ ActionController::Base.view_controller_internals = view_internals_old_value
258
+ ActionController::Base.protected_variables_cache = nil
202
259
  end
203
260
 
204
261
  def test_render_xml
@@ -226,9 +283,14 @@ class NewRenderTest < Test::Unit::TestCase
226
283
  assert_equal "Hello world!", @response.body
227
284
  end
228
285
 
286
+ def test_layout_overriding_layout
287
+ get :layout_overriding_layout
288
+ assert_no_match %r{<title>}, @response.body
289
+ end
290
+
229
291
  def test_rendering_nothing_on_layout
230
292
  get :rendering_nothing_on_layout
231
- assert_equal "", @response.body
293
+ assert_equal " ", @response.body
232
294
  end
233
295
 
234
296
  def test_render_xml_with_layouts
@@ -236,11 +298,6 @@ class NewRenderTest < Test::Unit::TestCase
236
298
  assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
237
299
  end
238
300
 
239
- # def test_partials_list
240
- # get :partials_list
241
- # assert_equal "goodbyeHello: davidHello: marygoodbye\n", @response.body
242
- # end
243
-
244
301
  def test_partial_only
245
302
  get :partial_only
246
303
  assert_equal "only partial", @response.body
@@ -287,4 +344,59 @@ class NewRenderTest < Test::Unit::TestCase
287
344
  def test_render_and_redirect
288
345
  assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
289
346
  end
347
+
348
+ def test_rendering_with_conflicting_local_vars
349
+ get :rendering_with_conflicting_local_vars
350
+ assert_equal("First: David\nSecond: Stephan\nThird: David\nFourth: David\nFifth: ", @response.body)
351
+ end
352
+
353
+ def test_action_talk_to_layout
354
+ get :action_talk_to_layout
355
+ assert_equal "<title>Talking to the layout</title>\nAction was here!", @response.body
356
+ end
357
+
358
+ def test_partials_list
359
+ get :partials_list
360
+ assert_equal "goodbyeHello: davidHello: marygoodbye\n", @response.body
361
+ end
362
+
363
+ def test_partial_with_locals
364
+ get :partial_with_locals
365
+ assert_equal "Hello: david", @response.body
366
+ end
367
+
368
+ def test_partial_collection
369
+ get :partial_collection
370
+ assert_equal "Hello: davidHello: mary", @response.body
371
+ end
372
+
373
+ def test_partial_collection_with_locals
374
+ get :partial_collection_with_locals
375
+ assert_equal "Bonjour: davidBonjour: mary", @response.body
376
+ end
377
+
378
+ def test_empty_partial_collection
379
+ get :empty_partial_collection
380
+ assert_equal " ", @response.body
381
+ end
382
+
383
+ def test_partial_with_hash_object
384
+ get :partial_with_hash_object
385
+ assert_equal "Sam", @response.body
386
+ end
387
+
388
+ def test_partial_with_implicit_local_assignment
389
+ get :partial_with_implicit_local_assignment
390
+ assert_equal "Hello: Marcel", @response.body
391
+ end
392
+
393
+ def test_render_text_with_assigns
394
+ get :render_text_with_assigns
395
+ assert_equal "world", assigns["hello"]
396
+ end
397
+
398
+ def test_yield_content_for
399
+ get :yield_content_for
400
+ assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body
401
+ end
290
402
  end