actionpack 2.0.5 → 2.1.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 (210) hide show
  1. data/CHANGELOG +149 -7
  2. data/MIT-LICENSE +1 -1
  3. data/README +1 -1
  4. data/Rakefile +5 -6
  5. data/lib/action_controller.rb +2 -2
  6. data/lib/action_controller/assertions/model_assertions.rb +2 -1
  7. data/lib/action_controller/assertions/response_assertions.rb +4 -2
  8. data/lib/action_controller/assertions/routing_assertions.rb +3 -3
  9. data/lib/action_controller/assertions/selector_assertions.rb +30 -27
  10. data/lib/action_controller/assertions/tag_assertions.rb +3 -3
  11. data/lib/action_controller/base.rb +103 -129
  12. data/lib/action_controller/benchmarking.rb +3 -3
  13. data/lib/action_controller/caching.rb +41 -652
  14. data/lib/action_controller/caching/actions.rb +144 -0
  15. data/lib/action_controller/caching/fragments.rb +138 -0
  16. data/lib/action_controller/caching/pages.rb +154 -0
  17. data/lib/action_controller/caching/sql_cache.rb +18 -0
  18. data/lib/action_controller/caching/sweeping.rb +97 -0
  19. data/lib/action_controller/cgi_ext/cookie.rb +27 -23
  20. data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
  21. data/lib/action_controller/cgi_process.rb +6 -4
  22. data/lib/action_controller/components.rb +7 -6
  23. data/lib/action_controller/cookies.rb +31 -19
  24. data/lib/action_controller/dispatcher.rb +51 -84
  25. data/lib/action_controller/filters.rb +295 -421
  26. data/lib/action_controller/flash.rb +1 -6
  27. data/lib/action_controller/headers.rb +31 -0
  28. data/lib/action_controller/helpers.rb +26 -9
  29. data/lib/action_controller/http_authentication.rb +1 -1
  30. data/lib/action_controller/integration.rb +65 -13
  31. data/lib/action_controller/layout.rb +24 -39
  32. data/lib/action_controller/mime_responds.rb +7 -3
  33. data/lib/action_controller/mime_type.rb +25 -9
  34. data/lib/action_controller/mime_types.rb +1 -1
  35. data/lib/action_controller/polymorphic_routes.rb +32 -17
  36. data/lib/action_controller/record_identifier.rb +10 -4
  37. data/lib/action_controller/request.rb +46 -30
  38. data/lib/action_controller/request_forgery_protection.rb +10 -9
  39. data/lib/action_controller/request_profiler.rb +29 -8
  40. data/lib/action_controller/rescue.rb +24 -24
  41. data/lib/action_controller/resources.rb +66 -23
  42. data/lib/action_controller/response.rb +2 -2
  43. data/lib/action_controller/routing.rb +113 -1229
  44. data/lib/action_controller/routing/builder.rb +204 -0
  45. data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
  46. data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
  47. data/lib/action_controller/routing/route.rb +240 -0
  48. data/lib/action_controller/routing/route_set.rb +435 -0
  49. data/lib/action_controller/routing/routing_ext.rb +46 -0
  50. data/lib/action_controller/routing/segments.rb +283 -0
  51. data/lib/action_controller/session/active_record_store.rb +13 -8
  52. data/lib/action_controller/session/cookie_store.rb +20 -17
  53. data/lib/action_controller/session_management.rb +10 -3
  54. data/lib/action_controller/streaming.rb +45 -31
  55. data/lib/action_controller/test_case.rb +33 -23
  56. data/lib/action_controller/test_process.rb +39 -35
  57. data/lib/action_controller/url_rewriter.rb +18 -12
  58. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
  59. data/lib/action_pack.rb +1 -1
  60. data/lib/action_pack/version.rb +2 -2
  61. data/lib/action_view.rb +11 -3
  62. data/lib/action_view/base.rb +73 -390
  63. data/lib/action_view/helpers/active_record_helper.rb +83 -62
  64. data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
  65. data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
  66. data/lib/action_view/helpers/benchmark_helper.rb +5 -3
  67. data/lib/action_view/helpers/cache_helper.rb +3 -2
  68. data/lib/action_view/helpers/capture_helper.rb +1 -2
  69. data/lib/action_view/helpers/date_helper.rb +104 -82
  70. data/lib/action_view/helpers/form_helper.rb +148 -75
  71. data/lib/action_view/helpers/form_options_helper.rb +44 -23
  72. data/lib/action_view/helpers/form_tag_helper.rb +22 -13
  73. data/lib/action_view/helpers/javascripts/controls.js +1 -1
  74. data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
  75. data/lib/action_view/helpers/javascripts/effects.js +1 -1
  76. data/lib/action_view/helpers/number_helper.rb +10 -3
  77. data/lib/action_view/helpers/prototype_helper.rb +61 -29
  78. data/lib/action_view/helpers/record_tag_helper.rb +3 -3
  79. data/lib/action_view/helpers/sanitize_helper.rb +23 -17
  80. data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
  81. data/lib/action_view/helpers/text_helper.rb +153 -125
  82. data/lib/action_view/helpers/url_helper.rb +83 -28
  83. data/lib/action_view/inline_template.rb +20 -0
  84. data/lib/action_view/partial_template.rb +70 -0
  85. data/lib/action_view/partials.rb +31 -73
  86. data/lib/action_view/template.rb +127 -0
  87. data/lib/action_view/template_error.rb +8 -7
  88. data/lib/action_view/template_finder.rb +177 -0
  89. data/lib/action_view/template_handler.rb +18 -1
  90. data/lib/action_view/template_handlers/builder.rb +10 -2
  91. data/lib/action_view/template_handlers/compilable.rb +128 -0
  92. data/lib/action_view/template_handlers/erb.rb +37 -2
  93. data/lib/action_view/template_handlers/rjs.rb +14 -1
  94. data/lib/action_view/test_case.rb +58 -0
  95. data/test/abstract_unit.rb +1 -1
  96. data/test/active_record_unit.rb +3 -6
  97. data/test/activerecord/active_record_store_test.rb +1 -2
  98. data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
  99. data/test/adv_attr_test.rb +20 -0
  100. data/test/controller/action_pack_assertions_test.rb +16 -19
  101. data/test/controller/addresses_render_test.rb +1 -1
  102. data/test/controller/assert_select_test.rb +13 -6
  103. data/test/controller/base_test.rb +48 -2
  104. data/test/controller/benchmark_test.rb +1 -2
  105. data/test/controller/caching_test.rb +282 -21
  106. data/test/controller/capture_test.rb +1 -1
  107. data/test/controller/cgi_test.rb +1 -1
  108. data/test/controller/components_test.rb +1 -1
  109. data/test/controller/content_type_test.rb +2 -2
  110. data/test/controller/cookie_test.rb +13 -2
  111. data/test/controller/custom_handler_test.rb +14 -10
  112. data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
  113. data/test/controller/dispatcher_test.rb +31 -49
  114. data/test/controller/fake_controllers.rb +17 -0
  115. data/test/controller/fake_models.rb +6 -0
  116. data/test/controller/filter_params_test.rb +14 -8
  117. data/test/controller/filters_test.rb +44 -16
  118. data/test/controller/flash_test.rb +2 -2
  119. data/test/controller/header_test.rb +14 -0
  120. data/test/controller/helper_test.rb +19 -15
  121. data/test/controller/html-scanner/document_test.rb +1 -2
  122. data/test/controller/html-scanner/node_test.rb +1 -2
  123. data/test/controller/html-scanner/sanitizer_test.rb +8 -5
  124. data/test/controller/html-scanner/tag_node_test.rb +1 -2
  125. data/test/controller/html-scanner/text_node_test.rb +2 -3
  126. data/test/controller/html-scanner/tokenizer_test.rb +8 -2
  127. data/test/controller/http_authentication_test.rb +1 -1
  128. data/test/controller/integration_test.rb +14 -16
  129. data/test/controller/integration_upload_test.rb +43 -0
  130. data/test/controller/layout_test.rb +26 -6
  131. data/test/controller/mime_responds_test.rb +39 -7
  132. data/test/controller/mime_type_test.rb +29 -5
  133. data/test/controller/new_render_test.rb +105 -34
  134. data/test/controller/polymorphic_routes_test.rb +32 -20
  135. data/test/controller/record_identifier_test.rb +38 -2
  136. data/test/controller/redirect_test.rb +21 -1
  137. data/test/controller/render_test.rb +59 -15
  138. data/test/controller/request_forgery_protection_test.rb +92 -5
  139. data/test/controller/request_test.rb +64 -6
  140. data/test/controller/rescue_test.rb +22 -6
  141. data/test/controller/resources_test.rb +102 -14
  142. data/test/controller/routing_test.rb +231 -19
  143. data/test/controller/selector_test.rb +2 -2
  144. data/test/controller/send_file_test.rb +14 -3
  145. data/test/controller/session/cookie_store_test.rb +16 -4
  146. data/test/controller/session/mem_cache_store_test.rb +3 -4
  147. data/test/controller/session_fixation_test.rb +1 -1
  148. data/test/controller/session_management_test.rb +23 -1
  149. data/test/controller/test_test.rb +39 -18
  150. data/test/controller/url_rewriter_test.rb +35 -1
  151. data/test/controller/verification_test.rb +1 -1
  152. data/test/controller/view_paths_test.rb +15 -12
  153. data/test/controller/webservice_test.rb +48 -3
  154. data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
  155. data/test/fixtures/company.rb +1 -0
  156. data/test/fixtures/customers/_customer.html.erb +1 -0
  157. data/test/fixtures/db_definitions/sqlite.sql +6 -0
  158. data/test/fixtures/functional_caching/_partial.erb +3 -0
  159. data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
  160. data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
  161. data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
  162. data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
  163. data/test/fixtures/mascot.rb +3 -0
  164. data/test/fixtures/mascots.yml +4 -0
  165. data/test/fixtures/mascots/_mascot.html.erb +1 -0
  166. data/test/fixtures/multipart/boundary_problem_file +10 -0
  167. data/test/fixtures/public/javascripts/application.js +1 -0
  168. data/test/fixtures/public/javascripts/controls.js +1 -0
  169. data/test/fixtures/public/javascripts/dragdrop.js +1 -0
  170. data/test/fixtures/public/javascripts/effects.js +1 -0
  171. data/test/fixtures/public/javascripts/prototype.js +1 -0
  172. data/test/fixtures/public/javascripts/version.1.0.js +1 -0
  173. data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
  174. data/test/fixtures/reply.rb +1 -0
  175. data/test/fixtures/shared.html.erb +1 -0
  176. data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
  177. data/test/fixtures/test/_customer_counter.erb +1 -0
  178. data/test/fixtures/test/_form.erb +1 -0
  179. data/test/fixtures/test/_labelling_form.erb +1 -0
  180. data/test/fixtures/test/_raise.html.erb +1 -0
  181. data/test/fixtures/test/greeting.js.rjs +1 -0
  182. data/test/fixtures/topics/_topic.html.erb +1 -0
  183. data/test/template/active_record_helper_test.rb +25 -8
  184. data/test/template/asset_tag_helper_test.rb +100 -17
  185. data/test/template/atom_feed_helper_test.rb +29 -1
  186. data/test/template/benchmark_helper_test.rb +10 -22
  187. data/test/template/date_helper_test.rb +455 -153
  188. data/test/template/erb_util_test.rb +10 -42
  189. data/test/template/form_helper_test.rb +192 -66
  190. data/test/template/form_options_helper_test.rb +19 -8
  191. data/test/template/form_tag_helper_test.rb +11 -8
  192. data/test/template/javascript_helper_test.rb +3 -9
  193. data/test/template/number_helper_test.rb +6 -3
  194. data/test/template/prototype_helper_test.rb +27 -40
  195. data/test/template/record_tag_helper_test.rb +54 -0
  196. data/test/template/sanitize_helper_test.rb +5 -6
  197. data/test/template/scriptaculous_helper_test.rb +7 -13
  198. data/test/template/tag_helper_test.rb +3 -6
  199. data/test/template/template_finder_test.rb +73 -0
  200. data/test/template/template_object_test.rb +95 -0
  201. data/test/template/test_test.rb +56 -0
  202. data/test/template/text_helper_test.rb +46 -33
  203. data/test/template/url_helper_test.rb +8 -10
  204. metadata +65 -12
  205. data/lib/action_view/compiled_templates.rb +0 -69
  206. data/test/action_view_test.rb +0 -44
  207. data/test/activerecord/fixtures_test.rb +0 -24
  208. data/test/controller/fragment_store_setting_test.rb +0 -47
  209. data/test/template/compiled_templates_test.rb +0 -197
  210. data/test/template/deprecate_ivars_test.rb +0 -51
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
  require 'digest/sha1'
3
3
 
4
4
  ActionController::Routing::Routes.draw do |map|
@@ -50,6 +50,14 @@ class CsrfCookieMonsterController < ActionController::Base
50
50
  protect_from_forgery :only => :index
51
51
  end
52
52
 
53
+ # sessions are turned off
54
+ class SessionOffController < ActionController::Base
55
+ protect_from_forgery :secret => 'foobar'
56
+ session :off
57
+ def rescue_action(e) raise e end
58
+ include RequestForgeryProtectionActions
59
+ end
60
+
53
61
  class FreeCookieController < CsrfCookieMonsterController
54
62
  self.allow_forgery_protection = false
55
63
 
@@ -93,19 +101,79 @@ module RequestForgeryProtectionTests
93
101
  post :unsafe
94
102
  assert_response :success
95
103
  end
96
-
104
+
97
105
  def test_should_not_allow_post_without_token
98
106
  assert_raises(ActionController::InvalidAuthenticityToken) { post :index }
99
107
  end
100
-
108
+
101
109
  def test_should_not_allow_put_without_token
102
110
  assert_raises(ActionController::InvalidAuthenticityToken) { put :index }
103
111
  end
104
-
112
+
105
113
  def test_should_not_allow_delete_without_token
106
114
  assert_raises(ActionController::InvalidAuthenticityToken) { delete :index }
107
115
  end
108
-
116
+
117
+ def test_should_not_allow_api_formatted_post_without_token
118
+ assert_raises(ActionController::InvalidAuthenticityToken) do
119
+ post :index, :format => 'xml'
120
+ end
121
+ end
122
+
123
+ def test_should_not_allow_api_formatted_put_without_token
124
+ assert_raises(ActionController::InvalidAuthenticityToken) do
125
+ put :index, :format => 'xml'
126
+ end
127
+ end
128
+
129
+ def test_should_not_allow_api_formatted_delete_without_token
130
+ assert_raises(ActionController::InvalidAuthenticityToken) do
131
+ delete :index, :format => 'xml'
132
+ end
133
+ end
134
+
135
+ def test_should_not_allow_api_formatted_post_sent_as_url_encoded_form_without_token
136
+ assert_raises(ActionController::InvalidAuthenticityToken) do
137
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
138
+ post :index, :format => 'xml'
139
+ end
140
+ end
141
+
142
+ def test_should_not_allow_api_formatted_put_sent_as_url_encoded_form_without_token
143
+ assert_raises(ActionController::InvalidAuthenticityToken) do
144
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
145
+ put :index, :format => 'xml'
146
+ end
147
+ end
148
+
149
+ def test_should_not_allow_api_formatted_delete_sent_as_url_encoded_form_without_token
150
+ assert_raises(ActionController::InvalidAuthenticityToken) do
151
+ @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
152
+ delete :index, :format => 'xml'
153
+ end
154
+ end
155
+
156
+ def test_should_not_allow_api_formatted_post_sent_as_multipart_form_without_token
157
+ assert_raises(ActionController::InvalidAuthenticityToken) do
158
+ @request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
159
+ post :index, :format => 'xml'
160
+ end
161
+ end
162
+
163
+ def test_should_not_allow_api_formatted_put_sent_as_multipart_form_without_token
164
+ assert_raises(ActionController::InvalidAuthenticityToken) do
165
+ @request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
166
+ put :index, :format => 'xml'
167
+ end
168
+ end
169
+
170
+ def test_should_not_allow_api_formatted_delete_sent_as_multipart_form_without_token
171
+ assert_raises(ActionController::InvalidAuthenticityToken) do
172
+ @request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
173
+ delete :index, :format => 'xml'
174
+ end
175
+ end
176
+
109
177
  def test_should_not_allow_xhr_post_without_token
110
178
  assert_raises(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
111
179
  end
@@ -134,16 +202,19 @@ module RequestForgeryProtectionTests
134
202
  end
135
203
 
136
204
  def test_should_allow_post_with_xml
205
+ @request.env['CONTENT_TYPE'] = Mime::XML.to_s
137
206
  post :index, :format => 'xml'
138
207
  assert_response :success
139
208
  end
140
209
 
141
210
  def test_should_allow_put_with_xml
211
+ @request.env['CONTENT_TYPE'] = Mime::XML.to_s
142
212
  put :index, :format => 'xml'
143
213
  assert_response :success
144
214
  end
145
215
 
146
216
  def test_should_allow_delete_with_xml
217
+ @request.env['CONTENT_TYPE'] = Mime::XML.to_s
147
218
  delete :index, :format => 'xml'
148
219
  assert_response :success
149
220
  end
@@ -224,3 +295,19 @@ class FreeCookieControllerTest < Test::Unit::TestCase
224
295
  end
225
296
  end
226
297
  end
298
+
299
+ class SessionOffControllerTest < Test::Unit::TestCase
300
+ def setup
301
+ @controller = SessionOffController.new
302
+ @request = ActionController::TestRequest.new
303
+ @response = ActionController::TestResponse.new
304
+ @token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
305
+ end
306
+
307
+ def test_should_raise_correct_exception
308
+ @request.session = {} # session(:off) doesn't appear to work with controller tests
309
+ assert_raises(ActionController::InvalidAuthenticityToken) do
310
+ post :index, :authenticity_token => @token
311
+ end
312
+ end
313
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
  require 'action_controller/integration'
3
3
 
4
4
  class RequestTest < Test::Unit::TestCase
@@ -622,7 +622,7 @@ class UrlEncodedRequestParameterParsingTest < Test::Unit::TestCase
622
622
  "ie_products[string]" => [ UploadedStringIO.new("Microsoft") ],
623
623
  "ie_products[file]" => [ ie_file ],
624
624
  "text_part" => [non_file_text_part]
625
- }
625
+ }
626
626
 
627
627
  expected_output = {
628
628
  "something" => "",
@@ -726,6 +726,18 @@ class UrlEncodedRequestParameterParsingTest < Test::Unit::TestCase
726
726
  expected = { "test2" => "value1" }
727
727
  assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input)
728
728
  end
729
+
730
+ def test_parse_params_with_array_prefix_and_hashes
731
+ input = { "a[][b][c]" => %w(d) }
732
+ expected = {"a" => [{"b" => {"c" => "d"}}]}
733
+ assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input)
734
+ end
735
+
736
+ def test_parse_params_with_complex_nesting
737
+ input = { "a[][b][c][][d][]" => %w(e) }
738
+ expected = {"a" => [{"b" => {"c" => [{"d" => ["e"]}]}}]}
739
+ assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input)
740
+ end
729
741
  end
730
742
 
731
743
 
@@ -753,13 +765,36 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
753
765
  assert_equal 'contents', file.read
754
766
  end
755
767
 
768
+ def test_boundary_problem_file
769
+ params = process('boundary_problem_file')
770
+ assert_equal %w(file foo), params.keys.sort
771
+
772
+ file = params['file']
773
+ foo = params['foo']
774
+
775
+ if RUBY_VERSION > '1.9'
776
+ assert_kind_of File, file
777
+ else
778
+ assert_kind_of Tempfile, file
779
+ end
780
+
781
+ assert_equal 'file.txt', file.original_filename
782
+ assert_equal "text/plain", file.content_type
783
+
784
+ assert_equal 'bar', foo
785
+ end
786
+
756
787
  def test_large_text_file
757
788
  params = process('large_text_file')
758
789
  assert_equal %w(file foo), params.keys.sort
759
790
  assert_equal 'bar', params['foo']
760
791
 
761
792
  file = params['file']
762
- assert_kind_of Tempfile, file
793
+ if RUBY_VERSION > '1.9'
794
+ assert_kind_of File, file
795
+ else
796
+ assert_kind_of Tempfile, file
797
+ end
763
798
  assert_equal 'file.txt', file.original_filename
764
799
  assert_equal "text/plain", file.content_type
765
800
  assert ('a' * 20480) == file.read
@@ -800,8 +835,10 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
800
835
  assert_equal 'bar', params['foo']
801
836
 
802
837
  # Ruby CGI doesn't handle multipart/mixed for us.
803
- assert_kind_of String, params['files']
804
- assert_equal 19756, params['files'].size
838
+ files = params['files']
839
+ assert_kind_of String, files
840
+ files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding)
841
+ assert_equal 19756, files.size
805
842
  end
806
843
 
807
844
  private
@@ -814,8 +851,13 @@ class MultipartRequestParameterParsingTest < Test::Unit::TestCase
814
851
  end
815
852
  end
816
853
 
817
-
818
854
  class XmlParamsParsingTest < Test::Unit::TestCase
855
+ def test_hash_params
856
+ person = parse_body("<person><name>David</name></person>")[:person]
857
+ assert_kind_of Hash, person
858
+ assert_equal 'David', person['name']
859
+ end
860
+
819
861
  def test_single_file
820
862
  person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>")
821
863
 
@@ -862,3 +904,19 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest
862
904
  ActionController::CgiRequest.new(cgi).request_parameters
863
905
  end
864
906
  end
907
+
908
+ class JsonParamsParsingTest < Test::Unit::TestCase
909
+ def test_hash_params
910
+ person = parse_body({:person => {:name => "David"}}.to_json)[:person]
911
+ assert_kind_of Hash, person
912
+ assert_equal 'David', person['name']
913
+ end
914
+
915
+ private
916
+ def parse_body(body)
917
+ env = { 'CONTENT_TYPE' => 'application/json',
918
+ 'CONTENT_LENGTH' => body.size.to_s }
919
+ cgi = ActionController::Integration::Session::StubCGI.new(env, body)
920
+ ActionController::CgiRequest.new(cgi).request_parameters
921
+ end
922
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
 
3
3
  uses_mocha 'rescue' do
4
4
 
@@ -279,7 +279,7 @@ class RescueTest < Test::Unit::TestCase
279
279
  assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates.default
280
280
  assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates[Exception.new]
281
281
 
282
- assert_equal 'missing_template', templates[ActionController::MissingTemplate.name]
282
+ assert_equal 'missing_template', templates[ActionView::MissingTemplate.name]
283
283
  assert_equal 'routing_error', templates[ActionController::RoutingError.name]
284
284
  assert_equal 'unknown_action', templates[ActionController::UnknownAction.name]
285
285
  assert_equal 'template_error', templates[ActionView::TemplateError.name]
@@ -305,7 +305,9 @@ class RescueTest < Test::Unit::TestCase
305
305
 
306
306
  def test_not_implemented
307
307
  with_all_requests_local false do
308
- head :not_implemented
308
+ with_rails_public_path(".") do
309
+ head :not_implemented
310
+ end
309
311
  end
310
312
  assert_response :not_implemented
311
313
  assert_equal "GET, PUT", @response.headers['Allow']
@@ -313,7 +315,9 @@ class RescueTest < Test::Unit::TestCase
313
315
 
314
316
  def test_method_not_allowed
315
317
  with_all_requests_local false do
316
- get :method_not_allowed
318
+ with_rails_public_path(".") do
319
+ get :method_not_allowed
320
+ end
317
321
  end
318
322
  assert_response :method_not_allowed
319
323
  assert_equal "GET, HEAD, PUT", @response.headers['Allow']
@@ -391,7 +395,19 @@ class RescueTest < Test::Unit::TestCase
391
395
  @request.remote_addr = old_remote_addr
392
396
  end
393
397
 
394
- def with_rails_root(path = nil)
398
+ def with_rails_public_path(rails_root)
399
+ old_rails = Object.const_get(:Rails) rescue nil
400
+ mod = Object.const_set(:Rails, Module.new)
401
+ (class << mod; self; end).instance_eval do
402
+ define_method(:public_path) { "#{rails_root}/public" }
403
+ end
404
+ yield
405
+ ensure
406
+ Object.module_eval { remove_const(:Rails) } if defined?(Rails)
407
+ Object.const_set(:Rails, old_rails) if old_rails
408
+ end
409
+
410
+ def with_rails_root(path = nil,&block)
395
411
  old_rails_root = RAILS_ROOT if defined?(RAILS_ROOT)
396
412
  if path
397
413
  silence_warnings { Object.const_set(:RAILS_ROOT, path) }
@@ -399,7 +415,7 @@ class RescueTest < Test::Unit::TestCase
399
415
  Object.remove_const(:RAILS_ROOT) rescue nil
400
416
  end
401
417
 
402
- yield
418
+ with_rails_public_path(path, &block)
403
419
 
404
420
  ensure
405
421
  if old_rails_root
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
 
3
3
  class ResourcesController < ActionController::Base
4
4
  def index() render :nothing => true end
@@ -76,6 +76,12 @@ class ResourcesTest < Test::Unit::TestCase
76
76
  end
77
77
  end
78
78
 
79
+ def test_override_paths_for_default_restful_actions
80
+ resource = ActionController::Resources::Resource.new(:messages,
81
+ :path_names => {:new => 'nuevo', :edit => 'editar'})
82
+ assert_equal resource.new_path, "#{resource.path}/nuevo"
83
+ end
84
+
79
85
  def test_multiple_default_restful_routes
80
86
  with_restful_routing :messages, :comments do
81
87
  assert_simply_restful_for :messages
@@ -203,6 +209,45 @@ class ResourcesTest < Test::Unit::TestCase
203
209
  end
204
210
  end
205
211
 
212
+ def test_member_when_override_paths_for_default_restful_actions_with
213
+ [:put, :post].each do |method|
214
+ with_restful_routing :messages, :member => { :mark => method }, :path_names => {:new => 'nuevo'} do
215
+ mark_options = {:action => 'mark', :id => '1', :controller => "messages"}
216
+ mark_path = "/messages/1/mark"
217
+
218
+ assert_restful_routes_for :messages, :path_names => {:new => 'nuevo'} do |options|
219
+ assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method)
220
+ end
221
+
222
+ assert_restful_named_routes_for :messages, :path_names => {:new => 'nuevo'} do |options|
223
+ assert_named_route mark_path, :mark_message_path, mark_options
224
+ end
225
+ end
226
+ end
227
+ end
228
+
229
+ def test_member_when_changed_default_restful_actions_and_path_names_not_specified
230
+ default_path_names = ActionController::Base.resources_path_names
231
+ ActionController::Base.resources_path_names = {:new => 'nuevo', :edit => 'editar'}
232
+
233
+ with_restful_routing :messages do
234
+ new_options = { :action => 'new', :controller => 'messages' }
235
+ new_path = "/messages/nuevo"
236
+ edit_options = { :action => 'edit', :id => '1', :controller => 'messages' }
237
+ edit_path = "/messages/1/editar"
238
+
239
+ assert_restful_routes_for :messages do |options|
240
+ assert_recognizes(options.merge(new_options), :path => new_path, :method => :get)
241
+ end
242
+
243
+ assert_restful_routes_for :messages do |options|
244
+ assert_recognizes(options.merge(edit_options), :path => edit_path, :method => :get)
245
+ end
246
+ end
247
+ ensure
248
+ ActionController::Base.resources_path_names = default_path_names
249
+ end
250
+
206
251
  def test_with_two_member_actions_with_same_method
207
252
  [:put, :post].each do |method|
208
253
  with_restful_routing :messages, :member => { :mark => method, :unmark => method } do
@@ -609,6 +654,35 @@ class ResourcesTest < Test::Unit::TestCase
609
654
  end
610
655
  end
611
656
 
657
+ def test_with_path_segment
658
+ with_restful_routing :messages, :as => 'reviews' do
659
+ assert_simply_restful_for :messages, :as => 'reviews'
660
+ end
661
+ end
662
+
663
+ def test_multiple_with_path_segment_and_controller
664
+ with_routing do |set|
665
+ set.draw do |map|
666
+ map.resources :products do |products|
667
+ products.resources :product_reviews, :as => 'reviews', :controller => 'messages'
668
+ end
669
+ map.resources :tutors do |tutors|
670
+ tutors.resources :tutor_reviews, :as => 'reviews', :controller => 'comments'
671
+ end
672
+ end
673
+
674
+ assert_simply_restful_for :product_reviews, :controller=>'messages', :as => 'reviews', :name_prefix => 'product_', :path_prefix => 'products/1/', :options => {:product_id => '1'}
675
+ assert_simply_restful_for :tutor_reviews,:controller=>'comments', :as => 'reviews', :name_prefix => 'tutor_', :path_prefix => 'tutors/1/', :options => {:tutor_id => '1'}
676
+ end
677
+ end
678
+
679
+ def test_with_path_segment_path_prefix_requirements
680
+ expected_options = {:controller => 'messages', :action => 'show', :thread_id => '1.1.1', :id => '1'}
681
+ with_restful_routing :messages, :as => 'comments',:path_prefix => '/thread/:thread_id', :requirements => { :thread_id => /[0-9]\.[0-9]\.[0-9]/ } do
682
+ assert_recognizes(expected_options, :path => 'thread/1.1.1/comments/1', :method => :get)
683
+ end
684
+ end
685
+
612
686
  protected
613
687
  def with_restful_routing(*args)
614
688
  with_routing do |set|
@@ -639,11 +713,18 @@ class ResourcesTest < Test::Unit::TestCase
639
713
  options[:options] ||= {}
640
714
  options[:options][:controller] = options[:controller] || controller_name.to_s
641
715
 
642
- collection_path = "/#{options[:path_prefix]}#{controller_name}"
716
+ new_action = ActionController::Base.resources_path_names[:new] || "new"
717
+ edit_action = ActionController::Base.resources_path_names[:edit] || "edit"
718
+ if options[:path_names]
719
+ new_action = options[:path_names][:new] if options[:path_names][:new]
720
+ edit_action = options[:path_names][:edit] if options[:path_names][:edit]
721
+ end
722
+
723
+ collection_path = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
643
724
  member_path = "#{collection_path}/1"
644
- new_path = "#{collection_path}/new"
645
- edit_member_path = "#{member_path}/edit"
646
- formatted_edit_member_path = "#{member_path}/edit.xml"
725
+ new_path = "#{collection_path}/#{new_action}"
726
+ edit_member_path = "#{member_path}/#{edit_action}"
727
+ formatted_edit_member_path = "#{member_path}/#{edit_action}.xml"
647
728
 
648
729
  with_options(options[:options]) do |controller|
649
730
  controller.assert_routing collection_path, :action => 'index'
@@ -692,18 +773,25 @@ class ResourcesTest < Test::Unit::TestCase
692
773
  get :index, options[:options]
693
774
  options[:options].delete :action
694
775
 
695
- full_prefix = "/#{options[:path_prefix]}#{controller_name}"
776
+ full_prefix = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
696
777
  name_prefix = options[:name_prefix]
697
-
778
+
779
+ new_action = "new"
780
+ edit_action = "edit"
781
+ if options[:path_names]
782
+ new_action = options[:path_names][:new] || "new"
783
+ edit_action = options[:path_names][:edit] || "edit"
784
+ end
785
+
698
786
  assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options]
699
787
  assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml')
700
788
  assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
701
789
  assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
702
790
 
703
- assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options]
704
- assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
705
- assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
706
- assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
791
+ assert_named_route "#{full_prefix}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", options[:options]
792
+ assert_named_route "#{full_prefix}/#{new_action}.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
793
+ assert_named_route "#{full_prefix}/1/#{edit_action}", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
794
+ assert_named_route "#{full_prefix}/1/#{edit_action}.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
707
795
 
708
796
  yield options[:options] if block_given?
709
797
  end
@@ -712,7 +800,7 @@ class ResourcesTest < Test::Unit::TestCase
712
800
  options[:options] ||= {}
713
801
  options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize
714
802
 
715
- full_path = "/#{options[:path_prefix]}#{singleton_name}"
803
+ full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}"
716
804
  new_path = "#{full_path}/new"
717
805
  edit_path = "#{full_path}/edit"
718
806
  formatted_edit_path = "#{full_path}/edit.xml"
@@ -751,7 +839,7 @@ class ResourcesTest < Test::Unit::TestCase
751
839
  get :show, options[:options]
752
840
  options[:options].delete :action
753
841
 
754
- full_path = "/#{options[:path_prefix]}#{singleton_name}"
842
+ full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}"
755
843
  name_prefix = options[:name_prefix]
756
844
 
757
845
  assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", options[:options]
@@ -784,4 +872,4 @@ class ResourcesTest < Test::Unit::TestCase
784
872
  end
785
873
  true
786
874
  end
787
- end
875
+ end