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,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
2
- require File.dirname(__FILE__) + '/fake_models'
1
+ require 'abstract_unit'
2
+ require 'controller/fake_models'
3
3
 
4
4
  class CustomersController < ActionController::Base
5
5
  end
@@ -17,6 +17,9 @@ module NewRenderTestHelper
17
17
  end
18
18
  end
19
19
 
20
+ class LabellingFormBuilder < ActionView::Helpers::FormBuilder
21
+ end
22
+
20
23
  class NewRenderTestController < ActionController::Base
21
24
  layout :determine_layout
22
25
 
@@ -75,11 +78,6 @@ class NewRenderTestController < ActionController::Base
75
78
  @secret = 'in the sauce'
76
79
  render :file => 'test/render_file_with_ivar', :use_full_path => true
77
80
  end
78
-
79
- def render_file_not_using_full_path_with_relative_path
80
- @secret = 'in the sauce'
81
- render :file => 'test/../test/render_file_with_ivar', :use_full_path => true
82
- end
83
81
 
84
82
  def render_file_not_using_full_path_with_dot_in_path
85
83
  @secret = 'in the sauce'
@@ -136,15 +134,50 @@ class NewRenderTestController < ActionController::Base
136
134
  def partial_with_locals
137
135
  render :partial => "customer", :locals => { :customer => Customer.new("david") }
138
136
  end
139
-
137
+
138
+ def partial_with_form_builder
139
+ render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, {}, Proc.new {})
140
+ end
141
+
142
+ def partial_with_form_builder_subclass
143
+ render :partial => LabellingFormBuilder.new(:post, nil, @template, {}, Proc.new {})
144
+ end
145
+
140
146
  def partial_collection
141
147
  render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
142
148
  end
149
+
150
+ def partial_collection_with_spacer
151
+ render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ]
152
+ end
153
+
154
+ def partial_collection_with_counter
155
+ render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
156
+ end
143
157
 
144
158
  def partial_collection_with_locals
145
159
  render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
146
160
  end
147
161
 
162
+ def partial_collection_shorthand_with_locals
163
+ render :partial => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
164
+ end
165
+
166
+ def partial_collection_shorthand_with_different_types_of_records
167
+ render :partial => [
168
+ BadCustomer.new("mark"),
169
+ GoodCustomer.new("craig"),
170
+ BadCustomer.new("john"),
171
+ GoodCustomer.new("zach"),
172
+ GoodCustomer.new("brandon"),
173
+ BadCustomer.new("dan") ],
174
+ :locals => { :greeting => "Bonjour" }
175
+ end
176
+
177
+ def partial_collection_shorthand_with_different_types_of_records_with_counter
178
+ partial_collection_shorthand_with_different_types_of_records
179
+ end
180
+
148
181
  def empty_partial_collection
149
182
  render :partial => "customer", :collection => []
150
183
  end
@@ -206,6 +239,18 @@ class NewRenderTestController < ActionController::Base
206
239
  render :inline => "Hello: <%= params[:name] %>"
207
240
  end
208
241
 
242
+ def accessing_request_in_template
243
+ render :inline => "Hello: <%= request.host %>"
244
+ end
245
+
246
+ def accessing_logger_in_template
247
+ render :inline => "<%= logger.class %>"
248
+ end
249
+
250
+ def accessing_action_name_in_template
251
+ render :inline => "<%= action_name %>"
252
+ end
253
+
209
254
  def accessing_params_in_template_with_layout
210
255
  render :layout => nil, :inline => "Hello: <%= params[:name] %>"
211
256
  end
@@ -477,11 +522,6 @@ class NewRenderTest < Test::Unit::TestCase
477
522
  assert_equal "The secret is in the sauce\n", @response.body
478
523
  end
479
524
 
480
- def test_render_file_not_using_full_path_with_relative_path
481
- get :render_file_not_using_full_path_with_relative_path
482
- assert_equal "The secret is in the sauce\n", @response.body
483
- end
484
-
485
525
  def test_render_file_not_using_full_path_with_dot_in_path
486
526
  get :render_file_not_using_full_path_with_dot_in_path
487
527
  assert_equal "The secret is in the sauce\n", @response.body
@@ -501,25 +541,18 @@ class NewRenderTest < Test::Unit::TestCase
501
541
  end
502
542
 
503
543
  def test_access_to_request_in_view
504
- view_internals_old_value = ActionController::Base.view_controller_internals
505
-
506
- ActionController::Base.view_controller_internals = false
507
- ActionController::Base.protected_variables_cache = nil
508
-
509
- get :hello_world
510
- assert !assigns.include?('request'), 'request should not be in assigns'
511
-
512
- ActionController::Base.view_controller_internals = true
513
- ActionController::Base.protected_variables_cache = nil
514
-
515
- get :hello_world
516
- assert !assigns.include?('request'), 'request should not be in assigns'
517
- assert_kind_of ActionController::AbstractRequest, assigns['_request']
518
- assert_kind_of ActionController::AbstractRequest, @response.template.request
544
+ get :accessing_request_in_template
545
+ assert_equal "Hello: www.nextangle.com", @response.body
546
+ end
519
547
 
520
- ensure
521
- ActionController::Base.view_controller_internals = view_internals_old_value
522
- ActionController::Base.protected_variables_cache = nil
548
+ def test_access_to_logger_in_view
549
+ get :accessing_logger_in_template
550
+ assert_equal "Logger", @response.body
551
+ end
552
+
553
+ def test_access_to_action_name_in_view
554
+ get :accessing_action_name_in_template
555
+ assert_equal "accessing_action_name_in_template", @response.body
523
556
  end
524
557
 
525
558
  def test_render_xml
@@ -544,6 +577,12 @@ EOS
544
577
  assert_equal "<p>This is grand!</p>\n", @response.body
545
578
  end
546
579
 
580
+ def test_render_with_default_from_accept_header
581
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
582
+ get :greeting
583
+ assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
584
+ end
585
+
547
586
  def test_render_rjs_with_default
548
587
  get :delete_with_js
549
588
  assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
@@ -617,7 +656,7 @@ EOS
617
656
  end
618
657
 
619
658
  def test_bad_render_to_string_still_throws_exception
620
- assert_raises(ActionController::MissingTemplate) { get :render_to_string_with_exception }
659
+ assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
621
660
  end
622
661
 
623
662
  def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
@@ -684,15 +723,47 @@ EOS
684
723
  assert_equal "Hello: david", @response.body
685
724
  end
686
725
 
726
+ def test_partial_with_form_builder
727
+ get :partial_with_form_builder
728
+ assert_match(/<label/, @response.body)
729
+ assert_template('test/_form')
730
+ end
731
+
732
+ def test_partial_with_form_builder_subclass
733
+ get :partial_with_form_builder_subclass
734
+ assert_match(/<label/, @response.body)
735
+ assert_template('test/_labelling_form')
736
+ end
737
+
687
738
  def test_partial_collection
688
739
  get :partial_collection
689
740
  assert_equal "Hello: davidHello: mary", @response.body
690
741
  end
691
-
742
+
743
+ def test_partial_collection_with_counter
744
+ get :partial_collection_with_counter
745
+ assert_equal "david1mary2", @response.body
746
+ end
747
+
692
748
  def test_partial_collection_with_locals
693
749
  get :partial_collection_with_locals
694
750
  assert_equal "Bonjour: davidBonjour: mary", @response.body
695
751
  end
752
+
753
+ def test_partial_collection_with_spacer
754
+ get :partial_collection_with_spacer
755
+ assert_equal "Hello: davidonly partialHello: mary", @response.body
756
+ end
757
+
758
+ def test_partial_collection_shorthand_with_locals
759
+ get :partial_collection_shorthand_with_locals
760
+ assert_equal "Bonjour: davidBonjour: mary", @response.body
761
+ end
762
+
763
+ def test_partial_collection_shorthand_with_different_types_of_records
764
+ get :partial_collection_shorthand_with_different_types_of_records
765
+ assert_equal "Bonjour bad customer: mark1Bonjour good customer: craig2Bonjour bad customer: john3Bonjour good customer: zach4Bonjour good customer: brandon5Bonjour bad customer: dan6", @response.body
766
+ end
696
767
 
697
768
  def test_empty_partial_collection
698
769
  get :empty_partial_collection
@@ -720,7 +791,7 @@ EOS
720
791
  end
721
792
 
722
793
  def test_render_missing_partial_template
723
- assert_raises(ActionView::ActionViewError) do
794
+ assert_raises(ActionView::MissingTemplate) do
724
795
  get :missing_partial
725
796
  end
726
797
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
 
3
3
  class Article
4
4
  attr_reader :id
@@ -10,16 +10,16 @@ class Article
10
10
  end
11
11
  end
12
12
 
13
- class Comment < Article
13
+ class Response < Article
14
14
  def post_id; 1 end
15
15
  end
16
16
 
17
17
  class Tag < Article
18
- def comment_id; 1 end
18
+ def response_id; 1 end
19
19
  end
20
20
 
21
21
  # TODO: test nested models
22
- class Comment::Nested < Comment; end
22
+ class Response::Nested < Response; end
23
23
 
24
24
  uses_mocha 'polymorphic URL helpers' do
25
25
  class PolymorphicRoutesTest < Test::Unit::TestCase
@@ -28,7 +28,7 @@ uses_mocha 'polymorphic URL helpers' do
28
28
 
29
29
  def setup
30
30
  @article = Article.new
31
- @comment = Comment.new
31
+ @response = Response.new
32
32
  end
33
33
 
34
34
  def test_with_record
@@ -65,22 +65,27 @@ uses_mocha 'polymorphic URL helpers' do
65
65
  formatted_polymorphic_url([@article, :pdf])
66
66
  end
67
67
 
68
- # TODO: should this work?
69
- def xtest_format_option
68
+ def test_format_option
70
69
  @article.save
71
- expects(:article_url).with(@article, :format => :pdf)
70
+ expects(:article_url).with(@article, :pdf)
72
71
  polymorphic_url(@article, :format => :pdf)
73
72
  end
74
73
 
74
+ def test_id_and_format_option
75
+ @article.save
76
+ expects(:article_url).with(:id => @article, :format => :pdf)
77
+ polymorphic_url(:id => @article, :format => :pdf)
78
+ end
79
+
75
80
  def test_with_nested
76
- @comment.save
77
- expects(:article_comment_url).with(@article, @comment)
78
- polymorphic_url([@article, @comment])
81
+ @response.save
82
+ expects(:article_response_url).with(@article, @response)
83
+ polymorphic_url([@article, @response])
79
84
  end
80
85
 
81
86
  def test_with_nested_unsaved
82
- expects(:article_comments_url).with(@article)
83
- polymorphic_url([@article, @comment])
87
+ expects(:article_responses_url).with(@article)
88
+ polymorphic_url([@article, @response])
84
89
  end
85
90
 
86
91
  def test_new_with_array_and_namespace
@@ -97,20 +102,20 @@ uses_mocha 'polymorphic URL helpers' do
97
102
  @article.save
98
103
  expects(:admin_article_url).with(@article)
99
104
  polymorphic_url([:admin, @article])
100
- expects(:admin_article_comments_url).with(@article)
101
- polymorphic_url([:admin, @article, @comment])
105
+ expects(:admin_article_responses_url).with(@article)
106
+ polymorphic_url([:admin, @article, @response])
102
107
  end
103
108
 
104
109
  def test_nested_with_array_and_namespace
105
- @comment.save
106
- expects(:admin_article_comment_url).with(@article, @comment)
107
- polymorphic_url([:admin, @article, @comment])
110
+ @response.save
111
+ expects(:admin_article_response_url).with(@article, @response)
112
+ polymorphic_url([:admin, @article, @response])
108
113
 
109
114
  # a ridiculously long named route tests correct ordering of namespaces and nesting:
110
115
  @tag = Tag.new
111
116
  @tag.save
112
- expects(:site_admin_article_comment_tag_url).with(@article, @comment, @tag)
113
- polymorphic_url([:site, :admin, @article, @comment, @tag])
117
+ expects(:site_admin_article_response_tag_url).with(@article, @response, @tag)
118
+ polymorphic_url([:site, :admin, @article, @response, @tag])
114
119
  end
115
120
 
116
121
  # TODO: Needs to be updated to correctly know about whether the object is in a hash or not
@@ -125,5 +130,12 @@ uses_mocha 'polymorphic URL helpers' do
125
130
  polymorphic_path(@article, :action => :new)
126
131
  end
127
132
 
133
+ def test_polymorphic_path_does_not_modify_arguments
134
+ expects(:admin_article_responses_url).with(@article)
135
+ path = [:admin, @article, @response]
136
+ assert_no_difference 'path.size' do
137
+ polymorphic_url(path)
138
+ end
139
+ end
128
140
  end
129
141
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
 
3
3
  class Comment
4
4
  attr_reader :id
@@ -57,6 +57,18 @@ class RecordIdentifierTest < Test::Unit::TestCase
57
57
  assert_equal expected, partial_path(Comment)
58
58
  end
59
59
 
60
+ def test_partial_path_with_namespaced_controller_path
61
+ expected = "admin/#{@plural}/#{@singular}"
62
+ assert_equal expected, partial_path(@record, "admin/posts")
63
+ assert_equal expected, partial_path(@klass, "admin/posts")
64
+ end
65
+
66
+ def test_partial_path_with_not_namespaced_controller_path
67
+ expected = "#{@plural}/#{@singular}"
68
+ assert_equal expected, partial_path(@record, "posts")
69
+ assert_equal expected, partial_path(@klass, "posts")
70
+ end
71
+
60
72
  def test_dom_class
61
73
  assert_equal @singular, dom_class(@record)
62
74
  end
@@ -100,4 +112,28 @@ class NestedRecordIdentifierTest < RecordIdentifierTest
100
112
  assert_equal expected, partial_path(@record)
101
113
  assert_equal expected, partial_path(Comment::Nested)
102
114
  end
103
- end
115
+
116
+ def test_partial_path_with_namespaced_controller_path
117
+ expected = "admin/comment/nesteds/nested"
118
+ assert_equal expected, partial_path(@record, "admin/posts")
119
+ assert_equal expected, partial_path(@klass, "admin/posts")
120
+ end
121
+
122
+ def test_partial_path_with_deeper_namespaced_controller_path
123
+ expected = "deeper/admin/comment/nesteds/nested"
124
+ assert_equal expected, partial_path(@record, "deeper/admin/posts")
125
+ assert_equal expected, partial_path(@klass, "deeper/admin/posts")
126
+ end
127
+
128
+ def test_partial_path_with_even_deeper_namespaced_controller_path
129
+ expected = "even/more/deeper/admin/comment/nesteds/nested"
130
+ assert_equal expected, partial_path(@record, "even/more/deeper/admin/posts")
131
+ assert_equal expected, partial_path(@klass, "even/more/deeper/admin/posts")
132
+ end
133
+
134
+ def test_partial_path_with_not_namespaced_controller_path
135
+ expected = "comment/nesteds/nested"
136
+ assert_equal expected, partial_path(@record, "posts")
137
+ assert_equal expected, partial_path(@klass, "posts")
138
+ end
139
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
1
+ require 'abstract_unit'
2
2
 
3
3
  class WorkshopsController < ActionController::Base
4
4
  end
@@ -65,6 +65,14 @@ class RedirectController < ActionController::Base
65
65
  redirect_to :action => "hello_world"
66
66
  end
67
67
 
68
+ def redirect_to_url
69
+ redirect_to "http://www.rubyonrails.org/"
70
+ end
71
+
72
+ def redirect_to_url_with_unescaped_query_string
73
+ redirect_to "http://dev.rubyonrails.org/query?status=new"
74
+ end
75
+
68
76
  def redirect_to_back
69
77
  redirect_to :back
70
78
  end
@@ -193,6 +201,18 @@ class RedirectTest < Test::Unit::TestCase
193
201
  assert_equal "world", assigns["hello"]
194
202
  end
195
203
 
204
+ def test_redirect_to_url
205
+ get :redirect_to_url
206
+ assert_response :redirect
207
+ assert_redirected_to "http://www.rubyonrails.org/"
208
+ end
209
+
210
+ def test_redirect_to_url_with_unescaped_query_string
211
+ get :redirect_to_url_with_unescaped_query_string
212
+ assert_response :redirect
213
+ assert_redirected_to "http://dev.rubyonrails.org/query?status=new"
214
+ end
215
+
196
216
  def test_redirect_to_back
197
217
  @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from"
198
218
  get :redirect_to_back
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/../abstract_unit'
2
- require File.dirname(__FILE__) + '/fake_models'
1
+ require 'abstract_unit'
2
+ require 'controller/fake_models'
3
3
 
4
4
  module Fun
5
5
  class GamesController < ActionController::Base
@@ -20,6 +20,18 @@ class TestController < ActionController::Base
20
20
  render :template => "test/hello_world"
21
21
  end
22
22
 
23
+ def render_hello_world_with_forward_slash
24
+ render :template => "/test/hello_world"
25
+ end
26
+
27
+ def render_template_in_top_directory
28
+ render :template => 'shared'
29
+ end
30
+
31
+ def render_template_in_top_directory_with_slash
32
+ render :template => '/shared'
33
+ end
34
+
23
35
  def render_hello_world_from_variable
24
36
  @person = "david"
25
37
  render :text => "hello #{@person}"
@@ -57,6 +69,12 @@ class TestController < ActionController::Base
57
69
  render :text => "hello world", :status => 404
58
70
  end
59
71
 
72
+ def render_custom_code_rjs
73
+ render :update, :status => 404 do |page|
74
+ page.replace :foo, :partial => 'partial'
75
+ end
76
+ end
77
+
60
78
  def render_text_with_nil
61
79
  render :text => nil
62
80
  end
@@ -82,6 +100,15 @@ class TestController < ActionController::Base
82
100
  render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
83
101
  end
84
102
 
103
+ def render_line_offset
104
+ begin
105
+ render :inline => '<% raise %>', :locals => {:foo => 'bar'}
106
+ rescue => exc
107
+ end
108
+ line = exc.backtrace.first
109
+ render :text => line
110
+ end
111
+
85
112
  def heading
86
113
  head :ok
87
114
  end
@@ -127,14 +154,6 @@ class TestController < ActionController::Base
127
154
  :locals => { :local_name => name }
128
155
  end
129
156
 
130
- def accessing_local_assigns_in_inline_template_with_string_keys
131
- name = params[:local_name]
132
- ActionView::Base.local_assigns_support_string_keys = true
133
- render :inline => "<%= 'Goodbye, ' + local_name %>",
134
- :locals => { "local_name" => name }
135
- ActionView::Base.local_assigns_support_string_keys = false
136
- end
137
-
138
157
  def formatted_html_erb
139
158
  end
140
159
 
@@ -221,6 +240,30 @@ class RenderTest < Test::Unit::TestCase
221
240
  assert_template "test/hello_world"
222
241
  end
223
242
 
243
+ def test_line_offset
244
+ get :render_line_offset
245
+ line = @response.body
246
+ assert(line =~ %r{:(\d+):})
247
+ assert_equal "1", $1
248
+ end
249
+
250
+ def test_render_with_forward_slash
251
+ get :render_hello_world_with_forward_slash
252
+ assert_template "test/hello_world"
253
+ end
254
+
255
+ def test_render_in_top_directory
256
+ get :render_template_in_top_directory
257
+ assert_template "shared"
258
+ assert_equal "Elastica", @response.body
259
+ end
260
+
261
+ def test_render_in_top_directory_with_slash
262
+ get :render_template_in_top_directory_with_slash
263
+ assert_template "shared"
264
+ assert_equal "Elastica", @response.body
265
+ end
266
+
224
267
  def test_render_from_variable
225
268
  get :render_hello_world_from_variable
226
269
  assert_equal "hello david", @response.body
@@ -271,6 +314,12 @@ class RenderTest < Test::Unit::TestCase
271
314
  assert_equal 'hello world', @response.body
272
315
  end
273
316
 
317
+ def test_render_custom_code_rjs
318
+ get :render_custom_code_rjs
319
+ assert_response 404
320
+ assert_equal %(Element.replace("foo", "partial html");), @response.body
321
+ end
322
+
274
323
  def test_render_text_with_nil
275
324
  get :render_text_with_nil
276
325
  assert_response 200
@@ -362,11 +411,6 @@ class RenderTest < Test::Unit::TestCase
362
411
  assert_equal "Goodbye, Local David", @response.body
363
412
  end
364
413
 
365
- def test_accessing_local_assigns_in_inline_template_with_string_keys
366
- get :accessing_local_assigns_in_inline_template_with_string_keys, :local_name => "Local David"
367
- assert_equal "Goodbye, Local David", @response.body
368
- end
369
-
370
414
  def test_render_200_should_set_etag
371
415
  get :render_hello_world_from_variable
372
416
  assert_equal etag_for("hello david"), @response.headers['ETag']