actionpack 1.11.2 → 1.12.0

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 (149) hide show
  1. data/CHANGELOG +392 -5
  2. data/lib/action_controller.rb +8 -4
  3. data/lib/action_controller/assertions.rb +9 -10
  4. data/lib/action_controller/base.rb +177 -88
  5. data/lib/action_controller/benchmarking.rb +5 -5
  6. data/lib/action_controller/caching.rb +44 -36
  7. data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
  8. data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
  9. data/lib/action_controller/cgi_process.rb +36 -24
  10. data/lib/action_controller/components.rb +152 -52
  11. data/lib/action_controller/dependencies.rb +1 -1
  12. data/lib/action_controller/deprecated_redirects.rb +2 -2
  13. data/lib/action_controller/deprecated_request_methods.rb +34 -0
  14. data/lib/action_controller/filters.rb +59 -19
  15. data/lib/action_controller/flash.rb +53 -47
  16. data/lib/action_controller/helpers.rb +2 -2
  17. data/lib/action_controller/integration.rb +524 -0
  18. data/lib/action_controller/layout.rb +58 -23
  19. data/lib/action_controller/mime_responds.rb +163 -0
  20. data/lib/action_controller/mime_type.rb +142 -0
  21. data/lib/action_controller/pagination.rb +13 -7
  22. data/lib/action_controller/request.rb +59 -56
  23. data/lib/action_controller/rescue.rb +1 -1
  24. data/lib/action_controller/routing.rb +29 -10
  25. data/lib/action_controller/scaffolding.rb +8 -0
  26. data/lib/action_controller/session/active_record_store.rb +21 -10
  27. data/lib/action_controller/session/mem_cache_store.rb +18 -12
  28. data/lib/action_controller/session_management.rb +30 -11
  29. data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
  30. data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
  31. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  32. data/lib/action_controller/test_process.rb +189 -118
  33. data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
  34. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
  35. data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
  36. data/lib/action_controller/vendor/xml_node.rb +97 -0
  37. data/lib/action_controller/verification.rb +2 -0
  38. data/lib/action_pack/version.rb +3 -3
  39. data/lib/action_view.rb +0 -2
  40. data/lib/action_view/base.rb +109 -36
  41. data/lib/action_view/compiled_templates.rb +1 -1
  42. data/lib/action_view/helpers/active_record_helper.rb +4 -2
  43. data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
  44. data/lib/action_view/helpers/capture_helper.rb +49 -12
  45. data/lib/action_view/helpers/date_helper.rb +14 -4
  46. data/lib/action_view/helpers/form_helper.rb +136 -20
  47. data/lib/action_view/helpers/form_options_helper.rb +29 -7
  48. data/lib/action_view/helpers/form_tag_helper.rb +22 -20
  49. data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
  50. data/lib/action_view/helpers/javascript_helper.rb +50 -446
  51. data/lib/action_view/helpers/javascripts/controls.js +95 -30
  52. data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
  53. data/lib/action_view/helpers/javascripts/effects.js +310 -211
  54. data/lib/action_view/helpers/javascripts/prototype.js +228 -28
  55. data/lib/action_view/helpers/number_helper.rb +9 -9
  56. data/lib/action_view/helpers/pagination_helper.rb +1 -1
  57. data/lib/action_view/helpers/prototype_helper.rb +900 -0
  58. data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
  59. data/lib/action_view/helpers/text_helper.rb +7 -6
  60. data/lib/action_view/helpers/url_helper.rb +23 -14
  61. data/lib/action_view/partials.rb +12 -4
  62. data/rakefile +13 -5
  63. data/test/abstract_unit.rb +4 -3
  64. data/test/active_record_unit.rb +88 -0
  65. data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
  66. data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
  67. data/test/activerecord/pagination_test.rb +161 -0
  68. data/test/controller/action_pack_assertions_test.rb +18 -15
  69. data/test/controller/base_test.rb +31 -42
  70. data/test/controller/benchmark_test.rb +8 -11
  71. data/test/controller/capture_test.rb +33 -1
  72. data/test/controller/cgi_test.rb +33 -0
  73. data/test/controller/custom_handler_test.rb +8 -0
  74. data/test/controller/fake_controllers.rb +9 -17
  75. data/test/controller/filters_test.rb +32 -3
  76. data/test/controller/flash_test.rb +26 -41
  77. data/test/controller/fragment_store_setting_test.rb +1 -1
  78. data/test/controller/layout_test.rb +73 -0
  79. data/test/controller/mime_responds_test.rb +257 -0
  80. data/test/controller/mime_type_test.rb +24 -0
  81. data/test/controller/new_render_test.rb +157 -1
  82. data/test/controller/redirect_test.rb +23 -0
  83. data/test/controller/render_test.rb +54 -56
  84. data/test/controller/request_test.rb +25 -0
  85. data/test/controller/routing_test.rb +74 -66
  86. data/test/controller/test_test.rb +66 -1
  87. data/test/controller/verification_test.rb +3 -1
  88. data/test/controller/webservice_test.rb +255 -0
  89. data/test/fixtures/companies.yml +24 -0
  90. data/test/fixtures/company.rb +9 -0
  91. data/test/fixtures/db_definitions/sqlite.sql +42 -0
  92. data/test/fixtures/developer.rb +7 -0
  93. data/test/fixtures/developers.yml +21 -0
  94. data/test/fixtures/developers_projects.yml +13 -0
  95. data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
  96. data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
  97. data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
  98. data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
  99. data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
  100. data/test/fixtures/multipart/mona_lisa.jpg +0 -0
  101. data/test/fixtures/project.rb +3 -0
  102. data/test/fixtures/projects.yml +7 -0
  103. data/test/fixtures/replies.yml +13 -0
  104. data/test/fixtures/reply.rb +5 -0
  105. data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
  106. data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
  107. data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
  108. data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
  109. data/test/fixtures/respond_to/using_defaults.rjs +1 -0
  110. data/test/fixtures/respond_to/using_defaults.rxml +1 -0
  111. data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
  112. data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
  113. data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
  114. data/test/fixtures/test/block_content_for.rhtml +2 -0
  115. data/test/fixtures/test/delete_with_js.rjs +2 -0
  116. data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
  117. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  118. data/test/fixtures/test/erb_content_for.rhtml +2 -0
  119. data/test/fixtures/test/hello_world.rxml +3 -0
  120. data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
  121. data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
  122. data/test/fixtures/topic.rb +3 -0
  123. data/test/fixtures/topics.yml +22 -0
  124. data/test/template/active_record_helper_test.rb +4 -0
  125. data/test/template/asset_tag_helper_test.rb +7 -2
  126. data/test/template/date_helper_test.rb +39 -2
  127. data/test/template/form_helper_test.rb +238 -5
  128. data/test/template/form_options_helper_test.rb +78 -0
  129. data/test/template/form_tag_helper_test.rb +11 -0
  130. data/test/template/java_script_macros_helper_test.rb +51 -6
  131. data/test/template/javascript_helper_test.rb +7 -153
  132. data/test/template/number_helper_test.rb +14 -13
  133. data/test/template/prototype_helper_test.rb +423 -0
  134. data/test/template/scriptaculous_helper_test.rb +90 -0
  135. data/test/template/text_helper_test.rb +12 -9
  136. data/test/template/url_helper_test.rb +31 -15
  137. metadata +291 -246
  138. data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
  139. data/lib/action_controller/upload_progress.rb +0 -473
  140. data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
  141. data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
  142. data/lib/action_view/vendor/builder.rb +0 -13
  143. data/lib/action_view/vendor/builder/blankslate.rb +0 -53
  144. data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
  145. data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
  146. data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
  147. data/test/controller/multipart_progress_testx.rb +0 -365
  148. data/test/controller/upload_progress_testx.rb +0 -89
  149. data/test/template/upload_progress_helper_testx.rb +0 -136
@@ -105,6 +105,19 @@ class RequestTest < Test::Unit::TestCase
105
105
  @request.relative_url_root = nil
106
106
  @request.env['SCRIPT_NAME'] = "/collaboration/hieraki"
107
107
  assert_equal "/collaboration/hieraki", @request.relative_url_root
108
+
109
+ @request.relative_url_root = nil
110
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
111
+ @request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3'
112
+ @request.env['RAILS_RELATIVE_URL_ROOT'] = "/hieraki"
113
+ assert_equal "/hieraki", @request.relative_url_root
114
+
115
+ # @env overrides path guess
116
+ @request.relative_url_root = nil
117
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
118
+ @request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text'
119
+ @request.env['RAILS_RELATIVE_URL_ROOT'] = "/real_url"
120
+ assert_equal "/real_url", @request.relative_url_root
108
121
  end
109
122
 
110
123
  def test_request_uri
@@ -237,5 +250,17 @@ class RequestTest < Test::Unit::TestCase
237
250
  assert @request.xml_http_request?
238
251
  assert @request.xhr?
239
252
  end
253
+
254
+ def test_reports_ssl
255
+ assert !@request.ssl?
256
+ @request.env['HTTPS'] = 'on'
257
+ assert @request.ssl?
258
+ end
259
+
260
+ def test_reports_ssl_when_proxied_via_lighttpd
261
+ assert !@request.ssl?
262
+ @request.env['HTTP_X_FORWARDED_PROTO'] = 'https'
263
+ assert @request.ssl?
264
+ end
240
265
 
241
266
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../abstract_unit'
2
- require File.dirname(__FILE__) + '/fake_controllers'
3
2
  require 'test/unit'
3
+ require File.dirname(__FILE__) + '/fake_controllers'
4
4
  require 'stringio'
5
5
 
6
6
  RunTimeTests = ARGV.include? 'time'
@@ -12,7 +12,7 @@ class SourceTests < Test::Unit::TestCase
12
12
  def setup
13
13
  @source = Source.new
14
14
  end
15
-
15
+
16
16
  def test_initial_state
17
17
  assert_equal [], source.lines
18
18
  assert_equal 0, source.indentation_level
@@ -54,7 +54,7 @@ class CodeGeneratorTests < Test::Unit::TestCase
54
54
  def setup
55
55
  @generator = CodeGenerator.new
56
56
  end
57
-
57
+
58
58
  def test_initial_state
59
59
  assert_equal [], generator.source.lines
60
60
  assert_equal [], generator.locals
@@ -124,7 +124,7 @@ class RecognitionTests < Test::Unit::TestCase
124
124
  def test_all_static
125
125
  c = %w(hello world how are you).collect {|str| Static.new(str)}
126
126
 
127
- g.result :controller, "::Controllers::ContentController", true
127
+ g.result :controller, "::ContentController", true
128
128
  g.constant_result :action, 'index'
129
129
 
130
130
  go c
@@ -133,19 +133,19 @@ class RecognitionTests < Test::Unit::TestCase
133
133
  assert_nil execute('hello/world/how')
134
134
  assert_nil execute('hello/world/how/are')
135
135
  assert_nil execute('hello/world/how/are/you/today')
136
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hello/world/how/are/you'))
136
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hello/world/how/are/you'))
137
137
  end
138
138
 
139
139
  def test_basic_dynamic
140
140
  c = [Static.new("hi"), Dynamic.new(:action)]
141
- g.result :controller, "::Controllers::ContentController", true
141
+ g.result :controller, "::ContentController", true
142
142
  go c
143
143
 
144
144
  assert_nil execute('boo')
145
145
  assert_nil execute('boo/blah')
146
146
  assert_nil execute('hi')
147
147
  assert_nil execute('hi/dude/what')
148
- assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude'))
148
+ assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
149
149
  end
150
150
 
151
151
  def test_basic_dynamic_backwards
@@ -163,33 +163,33 @@ class RecognitionTests < Test::Unit::TestCase
163
163
 
164
164
  def test_dynamic_with_default
165
165
  c = [Static.new("hi"), Dynamic.new(:action, :default => 'index')]
166
- g.result :controller, "::Controllers::ContentController", true
166
+ g.result :controller, "::ContentController", true
167
167
  go c
168
168
 
169
169
  assert_nil execute('boo')
170
170
  assert_nil execute('boo/blah')
171
171
  assert_nil execute('hi/dude/what')
172
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi'))
173
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index'))
174
- assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude'))
172
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi'))
173
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
174
+ assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
175
175
  end
176
176
 
177
177
  def test_dynamic_with_string_condition
178
178
  c = [Static.new("hi"), Dynamic.new(:action, :condition => 'index')]
179
- g.result :controller, "::Controllers::ContentController", true
179
+ g.result :controller, "::ContentController", true
180
180
  go c
181
181
 
182
182
  assert_nil execute('boo')
183
183
  assert_nil execute('boo/blah')
184
184
  assert_nil execute('hi')
185
185
  assert_nil execute('hi/dude/what')
186
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index'))
186
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
187
187
  assert_nil execute('hi/dude')
188
188
  end
189
189
 
190
190
  def test_dynamic_with_string_condition_backwards
191
191
  c = [Dynamic.new(:action, :condition => 'index'), Static.new("hi")]
192
- g.result :controller, "::Controllers::ContentController", true
192
+ g.result :controller, "::ContentController", true
193
193
  go c
194
194
 
195
195
  assert_nil execute('boo')
@@ -197,13 +197,13 @@ class RecognitionTests < Test::Unit::TestCase
197
197
  assert_nil execute('hi')
198
198
  assert_nil execute('dude/what/hi')
199
199
  assert_nil execute('index/what')
200
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('index/hi'))
200
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('index/hi'))
201
201
  assert_nil execute('dude/hi')
202
202
  end
203
203
 
204
204
  def test_dynamic_with_regexp_condition
205
205
  c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/)]
206
- g.result :controller, "::Controllers::ContentController", true
206
+ g.result :controller, "::ContentController", true
207
207
  go c
208
208
 
209
209
  assert_nil execute('boo')
@@ -213,13 +213,13 @@ class RecognitionTests < Test::Unit::TestCase
213
213
  assert_nil execute('hi/138708jkhdf')
214
214
  assert_nil execute('hi/dkjfl8792343dfsf')
215
215
  assert_nil execute('hi/dude/what')
216
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index'))
217
- assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude'))
216
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
217
+ assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
218
218
  end
219
219
 
220
220
  def test_dynamic_with_regexp_and_default
221
221
  c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/, :default => 'index')]
222
- g.result :controller, "::Controllers::ContentController", true
222
+ g.result :controller, "::ContentController", true
223
223
  go c
224
224
 
225
225
  assert_nil execute('boo')
@@ -227,39 +227,39 @@ class RecognitionTests < Test::Unit::TestCase
227
227
  assert_nil execute('hi/FOXY')
228
228
  assert_nil execute('hi/138708jkhdf')
229
229
  assert_nil execute('hi/dkjfl8792343dfsf')
230
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi'))
231
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index'))
232
- assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude'))
230
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi'))
231
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
232
+ assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
233
233
  assert_nil execute('hi/dude/what')
234
234
  end
235
235
 
236
236
  def test_path
237
237
  c = [Static.new("hi"), Path.new(:file)]
238
- g.result :controller, "::Controllers::ContentController", true
238
+ g.result :controller, "::ContentController", true
239
239
  g.constant_result :action, "download"
240
240
 
241
241
  go c
242
242
 
243
243
  assert_nil execute('boo')
244
244
  assert_nil execute('boo/blah')
245
- assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => []}, execute('hi'))
246
- assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
245
+ assert_equal({:controller => ::ContentController, :action => 'download', :file => []}, execute('hi'))
246
+ assert_equal({:controller => ::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
247
247
  execute('hi/books/agile_rails_dev.pdf'))
248
- assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('hi/dude'))
248
+ assert_equal({:controller => ::ContentController, :action => 'download', :file => ['dude']}, execute('hi/dude'))
249
249
  assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
250
250
  end
251
251
 
252
252
  def test_path_with_dynamic
253
253
  c = [Dynamic.new(:action), Path.new(:file)]
254
- g.result :controller, "::Controllers::ContentController", true
254
+ g.result :controller, "::ContentController", true
255
255
 
256
256
  go c
257
257
 
258
258
  assert_nil execute('')
259
- assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => []}, execute('download'))
260
- assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
259
+ assert_equal({:controller => ::ContentController, :action => 'download', :file => []}, execute('download'))
260
+ assert_equal({:controller => ::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
261
261
  execute('download/books/agile_rails_dev.pdf'))
262
- assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('download/dude'))
262
+ assert_equal({:controller => ::ContentController, :action => 'download', :file => ['dude']}, execute('download/dude'))
263
263
  assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
264
264
  end
265
265
 
@@ -287,8 +287,8 @@ class RecognitionTests < Test::Unit::TestCase
287
287
  assert_nil execute('hi/13870948')
288
288
  assert_nil execute('hi/content/dog')
289
289
  assert_nil execute('hi/admin/user/foo')
290
- assert_equal({:controller => ::Controllers::ContentController, :action => 'hi'}, execute('hi/content'))
291
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
290
+ assert_equal({:controller => ::ContentController, :action => 'hi'}, execute('hi/content'))
291
+ assert_equal({:controller => ::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
292
292
  end
293
293
 
294
294
  def test_controller_with_regexp
@@ -300,8 +300,8 @@ class RecognitionTests < Test::Unit::TestCase
300
300
  assert_nil execute('hi')
301
301
  assert_nil execute('hi/x')
302
302
  assert_nil execute('hi/content')
303
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
304
- assert_equal({:controller => ::Controllers::Admin::NewsFeedController, :action => 'hi'}, execute('hi/admin/news_feed'))
303
+ assert_equal({:controller => ::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
304
+ assert_equal({:controller => ::Admin::NewsFeedController, :action => 'hi'}, execute('hi/admin/news_feed'))
305
305
  assert_nil execute('hi/admin/user/foo')
306
306
  end
307
307
 
@@ -310,13 +310,13 @@ class RecognitionTests < Test::Unit::TestCase
310
310
  go c
311
311
 
312
312
  # Make sure we get the right answers
313
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('content'))
314
- assert_equal({:controller => ::Controllers::ContentController, :action => 'list'}, execute('content/list'))
315
- assert_equal({:controller => ::Controllers::ContentController, :action => 'show', :id => '10'}, execute('content/show/10'))
313
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute('content'))
314
+ assert_equal({:controller => ::ContentController, :action => 'list'}, execute('content/list'))
315
+ assert_equal({:controller => ::ContentController, :action => 'show', :id => '10'}, execute('content/show/10'))
316
316
 
317
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'index'}, execute('admin/user'))
318
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'list'}, execute('admin/user/list'))
319
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => 'nseckar'}, execute('admin/user/show/nseckar'))
317
+ assert_equal({:controller => ::Admin::UserController, :action => 'index'}, execute('admin/user'))
318
+ assert_equal({:controller => ::Admin::UserController, :action => 'list'}, execute('admin/user/list'))
319
+ assert_equal({:controller => ::Admin::UserController, :action => 'show', :id => 'nseckar'}, execute('admin/user/show/nseckar'))
320
320
 
321
321
  assert_nil execute('content/show/10/20')
322
322
  assert_nil execute('food')
@@ -357,7 +357,7 @@ class RecognitionTests < Test::Unit::TestCase
357
357
  end
358
358
 
359
359
  def test_default_route
360
- g.result :controller, "::Controllers::ContentController", true
360
+ g.result :controller, "::ContentController", true
361
361
  g.constant_result :action, 'index'
362
362
 
363
363
  go []
@@ -366,7 +366,7 @@ class RecognitionTests < Test::Unit::TestCase
366
366
  assert_nil execute('hello/world/how')
367
367
  assert_nil execute('hello/world/how/are')
368
368
  assert_nil execute('hello/world/how/are/you/today')
369
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute([]))
369
+ assert_equal({:controller => ::ContentController, :action => 'index'}, execute([]))
370
370
  end
371
371
  end
372
372
 
@@ -534,6 +534,8 @@ not_expired = true
534
534
  end
535
535
 
536
536
  class RouteTests < Test::Unit::TestCase
537
+
538
+
537
539
  def route(*args)
538
540
  @route = ::ActionController::Routing::Route.new(*args) unless args.empty?
539
541
  return @route
@@ -566,7 +568,7 @@ class RouteTests < Test::Unit::TestCase
566
568
  assert_nil rec('hello/turn')
567
569
  assert_nil rec('turn/world')
568
570
  assert_equal(
569
- {:known => 'known_value', :controller => ::Controllers::ContentController, :action => 'index'},
571
+ {:known => 'known_value', :controller => ::ContentController, :action => 'index'},
570
572
  rec('hello/world')
571
573
  )
572
574
 
@@ -582,8 +584,8 @@ class RouteTests < Test::Unit::TestCase
582
584
 
583
585
  assert_nil rec('hello')
584
586
  assert_nil rec('foo/bar')
585
- assert_equal({:controller => ::Controllers::ContentController, :action => 'show_person', :name => 'rails'}, rec('hello/rails'))
586
- assert_equal({:controller => ::Controllers::ContentController, :action => 'show_person', :name => 'Nicholas Seckar'}, rec('hello/Nicholas+Seckar'))
587
+ assert_equal({:controller => ::ContentController, :action => 'show_person', :name => 'rails'}, rec('hello/rails'))
588
+ assert_equal({:controller => ::ContentController, :action => 'show_person', :name => 'Nicholas Seckar'}, rec('hello/Nicholas+Seckar'))
587
589
 
588
590
  assert_nil gen(:controller => 'content', :action => 'show_dude', :name => 'rails')
589
591
  assert_nil gen(:controller => 'content', :action => 'show_person')
@@ -596,15 +598,15 @@ class RouteTests < Test::Unit::TestCase
596
598
  route ':controller/:action/:id', :action => 'index', :id => nil
597
599
  assert_nil rec('hello')
598
600
  assert_nil rec('foo bar')
599
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, rec('content'))
600
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'index'}, rec('admin/user'))
601
+ assert_equal({:controller => ::ContentController, :action => 'index'}, rec('content'))
602
+ assert_equal({:controller => ::Admin::UserController, :action => 'index'}, rec('admin/user'))
601
603
 
602
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'index'}, rec('admin/user/index'))
603
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'list'}, rec('admin/user/list'))
604
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}, rec('admin/user/show/10'))
604
+ assert_equal({:controller => ::Admin::UserController, :action => 'index'}, rec('admin/user/index'))
605
+ assert_equal({:controller => ::Admin::UserController, :action => 'list'}, rec('admin/user/list'))
606
+ assert_equal({:controller => ::Admin::UserController, :action => 'show', :id => '10'}, rec('admin/user/show/10'))
605
607
 
606
- assert_equal({:controller => ::Controllers::ContentController, :action => 'list'}, rec('content/list'))
607
- assert_equal({:controller => ::Controllers::ContentController, :action => 'show', :id => '10'}, rec('content/show/10'))
608
+ assert_equal({:controller => ::ContentController, :action => 'list'}, rec('content/list'))
609
+ assert_equal({:controller => ::ContentController, :action => 'show', :id => '10'}, rec('content/show/10'))
608
610
 
609
611
 
610
612
  assert_equal '/content', gen(:controller => 'content', :action => 'index')
@@ -627,11 +629,11 @@ class RouteSetTests < Test::Unit::TestCase
627
629
  end
628
630
 
629
631
  def test_default_setup
630
- assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}.stringify_keys, rs.recognize_path(%w(content)))
631
- assert_equal({:controller => ::Controllers::ContentController, :action => 'list'}.stringify_keys, rs.recognize_path(%w(content list)))
632
- assert_equal({:controller => ::Controllers::ContentController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(content show 10)))
632
+ assert_equal({:controller => ::ContentController, :action => 'index'}.stringify_keys, rs.recognize_path(%w(content)))
633
+ assert_equal({:controller => ::ContentController, :action => 'list'}.stringify_keys, rs.recognize_path(%w(content list)))
634
+ assert_equal({:controller => ::ContentController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(content show 10)))
633
635
 
634
- assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10)))
636
+ assert_equal({:controller => ::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10)))
635
637
 
636
638
  assert_equal ['/admin/user/show/10', []], rs.generate({:controller => 'admin/user', :action => 'show', :id => 10})
637
639
 
@@ -641,7 +643,7 @@ class RouteSetTests < Test::Unit::TestCase
641
643
  assert_equal ['/admin/stuff', []], rs.generate({:controller => 'stuff'}, {:controller => 'admin/user', :action => 'list', :id => '10'})
642
644
  assert_equal ['/stuff', []], rs.generate({:controller => '/stuff'}, {:controller => 'admin/user', :action => 'list', :id => '10'})
643
645
  end
644
-
646
+
645
647
  def test_ignores_leading_slash
646
648
  @rs.draw {|m| m.connect '/:controller/:action/:id'}
647
649
  test_default_setup
@@ -718,9 +720,9 @@ class RouteSetTests < Test::Unit::TestCase
718
720
  map.connect ':controller/:admintoken/:action/:id', :controller => /admin\/.+/
719
721
  map.connect ':controller/:action/:id'
720
722
  end
721
- assert_equal({:controller => ::Controllers::Admin::UserController, :admintoken => "foo", :action => "index"}.stringify_keys,
723
+ assert_equal({:controller => ::Admin::UserController, :admintoken => "foo", :action => "index"}.stringify_keys,
722
724
  rs.recognize_path(%w(admin user foo)))
723
- assert_equal({:controller => ::Controllers::ContentController, :action => "foo"}.stringify_keys,
725
+ assert_equal({:controller => ::ContentController, :action => "foo"}.stringify_keys,
724
726
  rs.recognize_path(%w(content foo)))
725
727
  assert_equal ['/admin/user/foo', []], rs.generate(:controller => "admin/user", :admintoken => "foo", :action => "index")
726
728
  assert_equal ['/content/foo',[]], rs.generate(:controller => "content", :action => "foo")
@@ -792,7 +794,6 @@ class RouteSetTests < Test::Unit::TestCase
792
794
  rs.path 'file/*path', :controller => 'content', :action => 'show_file'
793
795
  rs.connect ':controller/:action/:id'
794
796
  end
795
-
796
797
  results = rs.recognize_path %w(file hello+world how+are+you%3F)
797
798
  assert results, "Recognition should have succeeded"
798
799
  assert_equal ['hello world', 'how are you?'], results['path']
@@ -801,6 +802,13 @@ class RouteSetTests < Test::Unit::TestCase
801
802
  assert results, "Recognition should have succeeded"
802
803
  assert_equal [], results['path']
803
804
  end
805
+
806
+ def test_non_controllers_cannot_be_matched
807
+ rs.draw do
808
+ rs.connect ':controller/:action/:id'
809
+ end
810
+ assert_nil rs.recognize_path(%w(not_a show 10)), "Shouldn't recognize non-controllers as controllers!"
811
+ end
804
812
 
805
813
  def test_paths_do_not_accept_defaults
806
814
  assert_raises(ActionController::RoutingError) do
@@ -838,7 +846,7 @@ class RouteSetTests < Test::Unit::TestCase
838
846
  assert_equal ['/page', []], rs.generate(:controller => 'content', :action => 'show_page', :id => '1')
839
847
  assert_equal ['/page/10', []], rs.generate(:controller => 'content', :action => 'show_page', :id => 10)
840
848
 
841
- ctrl = ::Controllers::ContentController
849
+ ctrl = ::ContentController
842
850
 
843
851
  assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => 1}, rs.recognize_path(%w(page)))
844
852
  assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '1'}, rs.recognize_path(%w(page 1)))
@@ -850,12 +858,12 @@ class RouteSetTests < Test::Unit::TestCase
850
858
  end
851
859
 
852
860
  def test_recognition_with_uppercase_controller_name
853
- assert_equal({'controller' => ::Controllers::ContentController, 'action' => 'index'}, rs.recognize_path(%w(Content)))
854
- assert_equal({'controller' => ::Controllers::ContentController, 'action' => 'list'}, rs.recognize_path(%w(Content list)))
855
- assert_equal({'controller' => ::Controllers::ContentController, 'action' => 'show', 'id' => '10'}, rs.recognize_path(%w(Content show 10)))
861
+ assert_equal({'controller' => ::ContentController, 'action' => 'index'}, rs.recognize_path(%w(Content)))
862
+ assert_equal({'controller' => ::ContentController, 'action' => 'list'}, rs.recognize_path(%w(Content list)))
863
+ assert_equal({'controller' => ::ContentController, 'action' => 'show', 'id' => '10'}, rs.recognize_path(%w(Content show 10)))
856
864
 
857
- assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin NewsFeed)))
858
- assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin News_Feed)))
865
+ assert_equal({'controller' => ::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin NewsFeed)))
866
+ assert_equal({'controller' => ::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin News_Feed)))
859
867
  end
860
868
 
861
869
  def test_both_requirement_and_optional
@@ -7,7 +7,12 @@ class TestTest < Test::Unit::TestCase
7
7
  flash["test"] = ">#{flash["test"]}<"
8
8
  render :text => 'ignore me'
9
9
  end
10
-
10
+
11
+ def render_raw_post
12
+ raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank?
13
+ render :text => request.raw_post
14
+ end
15
+
11
16
  def test_params
12
17
  render :text => params.inspect
13
18
  end
@@ -44,6 +49,24 @@ HTML
44
49
  def test_remote_addr
45
50
  render :text => (request.remote_addr || "not specified")
46
51
  end
52
+
53
+ def test_file_upload
54
+ render :text => params[:file].size
55
+ end
56
+
57
+ def redirect_to_symbol
58
+ redirect_to :generate_url, :id => 5
59
+ end
60
+
61
+ private
62
+
63
+ def rescue_action(e)
64
+ raise e
65
+ end
66
+
67
+ def generate_url(opts)
68
+ url_for(opts.merge(:action => "test_uri"))
69
+ end
47
70
  end
48
71
 
49
72
  def setup
@@ -57,6 +80,14 @@ HTML
57
80
  ActionController::Routing::Routes.reload
58
81
  end
59
82
 
83
+ def test_raw_post_handling
84
+ params = {:page => {:name => 'page name'}, 'some key' => 123}
85
+ get :render_raw_post, params.dup
86
+
87
+ raw_post = params.map {|k,v| [CGI::escape(k.to_s), CGI::escape(v.to_s)].join('=')}.sort.join('&')
88
+ assert_equal raw_post, @response.body
89
+ end
90
+
60
91
  def test_process_without_flash
61
92
  process :set_flash
62
93
  assert_equal '><', flash['test']
@@ -327,6 +358,12 @@ HTML
327
358
  assert_nil @request.env['HTTP_X_REQUESTED_WITH']
328
359
  end
329
360
 
361
+ def test_header_properly_reset_after_get_request
362
+ get :test_params
363
+ @request.recycle!
364
+ assert_nil @request.instance_variable_get("@request_method")
365
+ end
366
+
330
367
  %w(controller response request).each do |variable|
331
368
  %w(get post put delete head process).each do |method|
332
369
  define_method("test_#{variable}_missing_for_#{method}_raises_error") do
@@ -343,4 +380,32 @@ HTML
343
380
  end
344
381
  end
345
382
  end
383
+
384
+ FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
385
+
386
+ def test_test_uploaded_file
387
+ filename = 'mona_lisa.jpg'
388
+ path = "#{FILES_DIR}/#{filename}"
389
+ content_type = 'image/png'
390
+
391
+ file = ActionController::TestUploadedFile.new(path, content_type)
392
+ assert_equal filename, file.original_filename
393
+ assert_equal content_type, file.content_type
394
+ assert_equal file.path, file.local_path
395
+ assert_equal File.read(path), file.read
396
+ end
397
+
398
+ def test_fixture_file_upload
399
+ post :test_file_upload, :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg")
400
+ assert_equal 159528, @response.body
401
+ end
402
+
403
+ def test_test_uploaded_file_exception_when_file_doesnt_exist
404
+ assert_raise(RuntimeError) { ActionController::TestUploadedFile.new('non_existent_file') }
405
+ end
406
+
407
+ def test_assert_redirected_to_symbol
408
+ get :redirect_to_symbol
409
+ assert_redirected_to :generate_url
410
+ end
346
411
  end