actionpack 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (200) hide show
  1. data/CHANGELOG +223 -7
  2. data/README +6 -12
  3. data/Rakefile +11 -11
  4. data/lib/action_controller.rb +9 -9
  5. data/lib/action_controller/assertions/response_assertions.rb +29 -78
  6. data/lib/action_controller/assertions/routing_assertions.rb +33 -33
  7. data/lib/action_controller/assertions/selector_assertions.rb +9 -5
  8. data/lib/action_controller/base.rb +227 -161
  9. data/lib/action_controller/benchmarking.rb +37 -24
  10. data/lib/action_controller/caching/actions.rb +53 -21
  11. data/lib/action_controller/caching/fragments.rb +10 -36
  12. data/lib/action_controller/caching/sweeping.rb +3 -3
  13. data/lib/action_controller/cgi_ext/session.rb +2 -22
  14. data/lib/action_controller/cgi_process.rb +8 -46
  15. data/lib/action_controller/components.rb +4 -1
  16. data/lib/action_controller/cookies.rb +10 -0
  17. data/lib/action_controller/dispatcher.rb +49 -15
  18. data/lib/action_controller/filters.rb +48 -10
  19. data/lib/action_controller/headers.rb +16 -14
  20. data/lib/action_controller/helpers.rb +2 -2
  21. data/lib/action_controller/http_authentication.rb +1 -1
  22. data/lib/action_controller/integration.rb +57 -60
  23. data/lib/action_controller/layout.rb +27 -53
  24. data/lib/action_controller/mime_responds.rb +5 -1
  25. data/lib/action_controller/mime_type.rb +64 -42
  26. data/lib/action_controller/mime_types.rb +2 -1
  27. data/lib/action_controller/performance_test.rb +16 -0
  28. data/lib/action_controller/polymorphic_routes.rb +16 -9
  29. data/lib/action_controller/rack_process.rb +303 -0
  30. data/lib/action_controller/request.rb +205 -97
  31. data/lib/action_controller/request_forgery_protection.rb +2 -2
  32. data/lib/action_controller/request_profiler.rb +0 -0
  33. data/lib/action_controller/rescue.rb +20 -115
  34. data/lib/action_controller/resources.rb +186 -83
  35. data/lib/action_controller/response.rb +140 -26
  36. data/lib/action_controller/routing.rb +28 -30
  37. data/lib/action_controller/routing/builder.rb +45 -54
  38. data/lib/action_controller/routing/optimisations.rb +31 -21
  39. data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
  40. data/lib/action_controller/routing/route.rb +162 -147
  41. data/lib/action_controller/routing/route_set.rb +8 -7
  42. data/lib/action_controller/routing/routing_ext.rb +4 -1
  43. data/lib/action_controller/routing/segments.rb +50 -21
  44. data/lib/action_controller/session/cookie_store.rb +3 -2
  45. data/lib/action_controller/session/drb_server.rb +7 -7
  46. data/lib/action_controller/session_management.rb +6 -2
  47. data/lib/action_controller/streaming.rb +15 -8
  48. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  49. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  50. data/lib/action_controller/test_case.rb +66 -2
  51. data/lib/action_controller/test_process.rb +71 -66
  52. data/lib/action_controller/translation.rb +13 -0
  53. data/lib/action_controller/url_rewriter.rb +90 -13
  54. data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
  55. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
  56. data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
  57. data/lib/action_controller/verification.rb +2 -2
  58. data/lib/action_pack/version.rb +1 -1
  59. data/lib/action_view.rb +19 -11
  60. data/lib/action_view/base.rb +184 -150
  61. data/lib/action_view/helpers.rb +38 -0
  62. data/lib/action_view/helpers/active_record_helper.rb +56 -27
  63. data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
  64. data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
  65. data/lib/action_view/helpers/benchmark_helper.rb +3 -3
  66. data/lib/action_view/helpers/cache_helper.rb +1 -2
  67. data/lib/action_view/helpers/capture_helper.rb +19 -44
  68. data/lib/action_view/helpers/date_helper.rb +486 -296
  69. data/lib/action_view/helpers/debug_helper.rb +20 -13
  70. data/lib/action_view/helpers/form_helper.rb +71 -30
  71. data/lib/action_view/helpers/form_options_helper.rb +15 -85
  72. data/lib/action_view/helpers/form_tag_helper.rb +61 -38
  73. data/lib/action_view/helpers/javascript_helper.rb +80 -89
  74. data/lib/action_view/helpers/number_helper.rb +179 -74
  75. data/lib/action_view/helpers/prototype_helper.rb +216 -201
  76. data/lib/action_view/helpers/record_tag_helper.rb +4 -5
  77. data/lib/action_view/helpers/sanitize_helper.rb +65 -33
  78. data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
  79. data/lib/action_view/helpers/tag_helper.rb +39 -22
  80. data/lib/action_view/helpers/text_helper.rb +212 -118
  81. data/lib/action_view/helpers/translation_helper.rb +21 -0
  82. data/lib/action_view/helpers/url_helper.rb +100 -58
  83. data/lib/action_view/inline_template.rb +13 -14
  84. data/lib/action_view/locale/en.yml +91 -0
  85. data/lib/action_view/partials.rb +100 -55
  86. data/lib/action_view/paths.rb +125 -0
  87. data/lib/action_view/renderable.rb +102 -0
  88. data/lib/action_view/renderable_partial.rb +48 -0
  89. data/lib/action_view/template.rb +90 -101
  90. data/lib/action_view/template_error.rb +11 -21
  91. data/lib/action_view/template_handler.rb +8 -28
  92. data/lib/action_view/template_handlers.rb +45 -0
  93. data/lib/action_view/template_handlers/builder.rb +5 -15
  94. data/lib/action_view/template_handlers/erb.rb +9 -6
  95. data/lib/action_view/template_handlers/rjs.rb +2 -17
  96. data/lib/action_view/test_case.rb +7 -4
  97. data/test/abstract_unit.rb +4 -1
  98. data/test/active_record_unit.rb +28 -30
  99. data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
  100. data/test/controller/action_pack_assertions_test.rb +8 -37
  101. data/test/controller/addresses_render_test.rb +0 -3
  102. data/test/controller/assert_select_test.rb +51 -24
  103. data/test/controller/base_test.rb +4 -4
  104. data/test/controller/caching_test.rb +136 -66
  105. data/test/controller/capture_test.rb +1 -21
  106. data/test/controller/cgi_test.rb +157 -10
  107. data/test/controller/components_test.rb +41 -25
  108. data/test/controller/content_type_test.rb +49 -17
  109. data/test/controller/cookie_test.rb +1 -1
  110. data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
  111. data/test/controller/dispatcher_test.rb +9 -1
  112. data/test/controller/filter_params_test.rb +2 -2
  113. data/test/controller/filters_test.rb +13 -13
  114. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  115. data/test/controller/html-scanner/node_test.rb +21 -0
  116. data/test/controller/html-scanner/sanitizer_test.rb +14 -0
  117. data/test/controller/integration_test.rb +167 -6
  118. data/test/controller/layout_test.rb +11 -68
  119. data/test/controller/logging_test.rb +46 -0
  120. data/test/controller/mime_responds_test.rb +61 -59
  121. data/test/controller/mime_type_test.rb +6 -6
  122. data/test/controller/polymorphic_routes_test.rb +37 -2
  123. data/test/controller/rack_test.rb +323 -0
  124. data/test/controller/redirect_test.rb +72 -71
  125. data/test/controller/render_test.rb +1120 -108
  126. data/test/controller/request_forgery_protection_test.rb +66 -52
  127. data/test/controller/request_test.rb +103 -146
  128. data/test/controller/rescue_test.rb +20 -24
  129. data/test/controller/resources_test.rb +408 -25
  130. data/test/controller/routing_test.rb +1774 -1774
  131. data/test/controller/send_file_test.rb +0 -4
  132. data/test/controller/session/cookie_store_test.rb +53 -1
  133. data/test/controller/test_test.rb +15 -37
  134. data/test/controller/translation_test.rb +26 -0
  135. data/test/controller/url_rewriter_test.rb +27 -28
  136. data/test/controller/view_paths_test.rb +48 -47
  137. data/test/fixtures/_top_level_partial.html.erb +1 -0
  138. data/test/fixtures/_top_level_partial_only.erb +1 -0
  139. data/test/fixtures/developers/_developer.erb +1 -0
  140. data/test/fixtures/fun/games/_game.erb +1 -0
  141. data/test/fixtures/fun/serious/games/_game.erb +1 -0
  142. data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
  143. data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
  144. data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
  145. data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
  146. data/test/fixtures/layouts/_column.html.erb +2 -0
  147. data/test/fixtures/projects/_project.erb +1 -0
  148. data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
  149. data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
  150. data/test/fixtures/replies/_reply.erb +1 -0
  151. data/test/fixtures/test/_counter.html.erb +1 -0
  152. data/test/fixtures/test/_customer.erb +1 -1
  153. data/test/fixtures/test/_customer_with_var.erb +1 -0
  154. data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
  155. data/test/fixtures/test/_local_inspector.html.erb +1 -0
  156. data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
  157. data/test/fixtures/test/hello.builder +1 -1
  158. data/test/fixtures/test/hyphen-ated.erb +1 -0
  159. data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
  160. data/test/fixtures/test/nested_layout.erb +3 -0
  161. data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
  162. data/test/fixtures/test/sub_template_raise.html.erb +1 -0
  163. data/test/fixtures/test/template.erb +1 -0
  164. data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
  165. data/test/template/active_record_helper_i18n_test.rb +46 -0
  166. data/test/template/active_record_helper_test.rb +24 -24
  167. data/test/template/asset_tag_helper_test.rb +161 -29
  168. data/test/template/atom_feed_helper_test.rb +114 -5
  169. data/test/template/compiled_templates_test.rb +59 -0
  170. data/test/template/date_helper_i18n_test.rb +113 -0
  171. data/test/template/date_helper_test.rb +403 -109
  172. data/test/template/form_helper_test.rb +213 -154
  173. data/test/template/form_options_helper_test.rb +249 -897
  174. data/test/template/form_tag_helper_test.rb +80 -32
  175. data/test/template/javascript_helper_test.rb +17 -18
  176. data/test/template/number_helper_i18n_test.rb +54 -0
  177. data/test/template/number_helper_test.rb +43 -13
  178. data/test/template/prototype_helper_test.rb +101 -84
  179. data/test/template/record_tag_helper_test.rb +24 -20
  180. data/test/template/render_test.rb +193 -0
  181. data/test/template/sanitize_helper_test.rb +3 -3
  182. data/test/template/tag_helper_test.rb +34 -14
  183. data/test/template/text_helper_test.rb +83 -9
  184. data/test/template/translation_helper_test.rb +28 -0
  185. data/test/template/url_helper_test.rb +55 -18
  186. metadata +57 -18
  187. data/lib/action_view/helpers/javascripts/controls.js +0 -963
  188. data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
  189. data/lib/action_view/helpers/javascripts/effects.js +0 -1120
  190. data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
  191. data/lib/action_view/partial_template.rb +0 -70
  192. data/lib/action_view/template_finder.rb +0 -177
  193. data/lib/action_view/template_handlers/compilable.rb +0 -128
  194. data/test/controller/custom_handler_test.rb +0 -45
  195. data/test/controller/new_render_test.rb +0 -945
  196. data/test/fixtures/test/block_content_for.erb +0 -2
  197. data/test/fixtures/test/erb_content_for.erb +0 -2
  198. data/test/template/deprecated_erb_variable_test.rb +0 -9
  199. data/test/template/template_finder_test.rb +0 -73
  200. data/test/template/template_object_test.rb +0 -95
@@ -60,7 +60,7 @@ class CookieTest < Test::Unit::TestCase
60
60
  end
61
61
 
62
62
  def test_setting_cookie_for_fourteen_days_with_symbols
63
- get :authenticate_for_fourteen_days
63
+ get :authenticate_for_fourteen_days_with_symbols
64
64
  assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"]
65
65
  end
66
66
 
@@ -2,7 +2,6 @@ require 'abstract_unit'
2
2
 
3
3
  class DeprecatedBaseMethodsTest < Test::Unit::TestCase
4
4
  class Target < ActionController::Base
5
-
6
5
  def home_url(greeting)
7
6
  "http://example.com/#{greeting}"
8
7
  end
@@ -14,8 +13,6 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
14
13
  def rescue_action(e) raise e end
15
14
  end
16
15
 
17
- Target.view_paths = [ File.dirname(__FILE__) + "/../../fixtures" ]
18
-
19
16
  def setup
20
17
  @request = ActionController::TestRequest.new
21
18
  @response = ActionController::TestResponse.new
@@ -26,9 +26,17 @@ class DispatcherTest < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  def test_clears_dependencies_after_dispatch_if_in_loading_mode
29
- ActionController::Routing::Routes.expects(:reload).once
30
29
  ActiveSupport::Dependencies.expects(:clear).once
30
+ dispatch(@output, false)
31
+ end
32
+
33
+ def test_reloads_routes_before_dispatch_if_in_loading_mode
34
+ ActionController::Routing::Routes.expects(:reload).once
35
+ dispatch(@output, false)
36
+ end
31
37
 
38
+ def test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode
39
+ ActionView::Helpers::AssetTagHelper::AssetTag::Cache.expects(:clear).once
32
40
  dispatch(@output, false)
33
41
  end
34
42
 
@@ -27,7 +27,7 @@ class FilterParamTest < Test::Unit::TestCase
27
27
 
28
28
  test_hashes.each do |before_filter, after_filter, filter_words|
29
29
  FilterParamController.filter_parameter_logging(*filter_words)
30
- assert_equal after_filter, @controller.send!(:filter_parameters, before_filter)
30
+ assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
31
31
 
32
32
  filter_words.push('blah')
33
33
  FilterParamController.filter_parameter_logging(*filter_words) do |key, value|
@@ -37,7 +37,7 @@ class FilterParamTest < Test::Unit::TestCase
37
37
  before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
38
38
  after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
39
39
 
40
- assert_equal after_filter, @controller.send!(:filter_parameters, before_filter)
40
+ assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
41
41
  end
42
42
  end
43
43
 
@@ -111,15 +111,15 @@ class FilterTest < Test::Unit::TestCase
111
111
  end
112
112
 
113
113
  class OnlyConditionProcController < ConditionalFilterController
114
- before_filter(:only => :show) {|c| c.assigns["ran_proc_filter"] = true }
114
+ before_filter(:only => :show) {|c| c.instance_variable_set(:"@ran_proc_filter", true) }
115
115
  end
116
116
 
117
117
  class ExceptConditionProcController < ConditionalFilterController
118
- before_filter(:except => :show_without_filter) {|c| c.assigns["ran_proc_filter"] = true }
118
+ before_filter(:except => :show_without_filter) {|c| c.instance_variable_set(:"@ran_proc_filter", true) }
119
119
  end
120
120
 
121
121
  class ConditionalClassFilter
122
- def self.filter(controller) controller.assigns["ran_class_filter"] = true end
122
+ def self.filter(controller) controller.instance_variable_set(:"@ran_class_filter", true) end
123
123
  end
124
124
 
125
125
  class OnlyConditionClassController < ConditionalFilterController
@@ -131,7 +131,7 @@ class FilterTest < Test::Unit::TestCase
131
131
  end
132
132
 
133
133
  class AnomolousYetValidConditionController < ConditionalFilterController
134
- before_filter(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.assigns["ran_proc_filter1"] = true }, :except => :show_without_filter) { |c| c.assigns["ran_proc_filter2"] = true}
134
+ before_filter(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.instance_variable_set(:"@ran_proc_filter1", true)}, :except => :show_without_filter) { |c| c.instance_variable_set(:"@ran_proc_filter2", true)}
135
135
  end
136
136
 
137
137
  class ConditionalOptionsFilter < ConditionalFilterController
@@ -225,16 +225,16 @@ class FilterTest < Test::Unit::TestCase
225
225
  end
226
226
 
227
227
  class ProcController < PrependingController
228
- before_filter(proc { |c| c.assigns["ran_proc_filter"] = true })
228
+ before_filter(proc { |c| c.instance_variable_set(:"@ran_proc_filter", true) })
229
229
  end
230
230
 
231
231
  class ImplicitProcController < PrependingController
232
- before_filter { |c| c.assigns["ran_proc_filter"] = true }
232
+ before_filter { |c| c.instance_variable_set(:"@ran_proc_filter", true) }
233
233
  end
234
234
 
235
235
  class AuditFilter
236
236
  def self.filter(controller)
237
- controller.assigns["was_audited"] = true
237
+ controller.instance_variable_set(:"@was_audited", true)
238
238
  end
239
239
  end
240
240
 
@@ -242,12 +242,12 @@ class FilterTest < Test::Unit::TestCase
242
242
  def before(controller)
243
243
  @execution_log = "before"
244
244
  controller.class.execution_log << " before aroundfilter " if controller.respond_to? :execution_log
245
- controller.assigns["before_ran"] = true
245
+ controller.instance_variable_set(:"@before_ran", true)
246
246
  end
247
247
 
248
248
  def after(controller)
249
- controller.assigns["execution_log"] = @execution_log + " and after"
250
- controller.assigns["after_ran"] = true
249
+ controller.instance_variable_set(:"@execution_log", @execution_log + " and after")
250
+ controller.instance_variable_set(:"@after_ran", true)
251
251
  controller.class.execution_log << " after aroundfilter " if controller.respond_to? :execution_log
252
252
  end
253
253
  end
@@ -364,7 +364,7 @@ class FilterTest < Test::Unit::TestCase
364
364
  begin
365
365
  yield
366
366
  rescue ErrorToRescue => ex
367
- controller.send! :render, :text => "I rescued this: #{ex.inspect}"
367
+ controller.__send__ :render, :text => "I rescued this: #{ex.inspect}"
368
368
  end
369
369
  end
370
370
  end
@@ -726,9 +726,9 @@ end
726
726
 
727
727
  class ControllerWithProcFilter < PostsController
728
728
  around_filter(:only => :no_raise) do |c,b|
729
- c.assigns['before'] = true
729
+ c.instance_variable_set(:"@before", true)
730
730
  b.call
731
- c.assigns['after'] = true
731
+ c.instance_variable_set(:"@after", true)
732
732
  end
733
733
  end
734
734
 
@@ -0,0 +1,15 @@
1
+ require 'abstract_unit'
2
+
3
+ class CDATANodeTest < Test::Unit::TestCase
4
+ def setup
5
+ @node = HTML::CDATA.new(nil, 0, 0, "<p>howdy</p>")
6
+ end
7
+
8
+ def test_to_s
9
+ assert_equal "<![CDATA[<p>howdy</p>]]>", @node.to_s
10
+ end
11
+
12
+ def test_content
13
+ assert_equal "<p>howdy</p>", @node.content
14
+ end
15
+ end
@@ -65,4 +65,25 @@ class NodeTest < Test::Unit::TestCase
65
65
  assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
66
66
  assert node.attributes.has_key?("onmouseover")
67
67
  end
68
+
69
+ def test_parse_with_valid_cdata_section
70
+ s = "<![CDATA[<span>contents</span>]]>"
71
+ node = nil
72
+ assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
73
+ assert_kind_of HTML::CDATA, node
74
+ assert_equal '<span>contents</span>', node.content
75
+ end
76
+
77
+ def test_parse_strict_with_unterminated_cdata_section
78
+ s = "<![CDATA[neverending..."
79
+ assert_raise(RuntimeError) { HTML::Node.parse(nil,0,0,s) }
80
+ end
81
+
82
+ def test_parse_relaxed_with_unterminated_cdata_section
83
+ s = "<![CDATA[neverending..."
84
+ node = nil
85
+ assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) }
86
+ assert_kind_of HTML::CDATA, node
87
+ assert_equal 'neverending...', node.content
88
+ end
68
89
  end
@@ -17,6 +17,8 @@ class SanitizerTest < Test::Unit::TestCase
17
17
  %{This is a test.\n\n\nIt no longer contains any HTML.\n}, sanitizer.sanitize(
18
18
  %{<title>This is <b>a <a href="" target="_blank">test</a></b>.</title>\n\n<!-- it has a comment -->\n\n<p>It no <b>longer <strong>contains <em>any <strike>HTML</strike></em>.</strong></b></p>\n}))
19
19
  assert_equal "This has a here.", sanitizer.sanitize("This has a <!-- comment --> here.")
20
+ assert_equal "This has a here.", sanitizer.sanitize("This has a <![CDATA[<section>]]> here.")
21
+ assert_equal "This has an unclosed ", sanitizer.sanitize("This has an unclosed <![CDATA[<section>]] here...")
20
22
  [nil, '', ' '].each { |blank| assert_equal blank, sanitizer.sanitize(blank) }
21
23
  end
22
24
 
@@ -243,6 +245,18 @@ class SanitizerTest < Test::Unit::TestCase
243
245
  assert_sanitized %(<img src='vbscript:msgbox("XSS")' />), '<img />'
244
246
  end
245
247
 
248
+ def test_should_sanitize_cdata_section
249
+ assert_sanitized "<![CDATA[<span>section</span>]]>", "&lt;![CDATA[&lt;span>section&lt;/span>]]>"
250
+ end
251
+
252
+ def test_should_sanitize_unterminated_cdata_section
253
+ assert_sanitized "<![CDATA[<span>neverending...", "&lt;![CDATA[&lt;span>neverending...]]>"
254
+ end
255
+
256
+ def test_should_not_mangle_urls_with_ampersand
257
+ assert_sanitized %{<a href=\"http://www.domain.com?var1=1&amp;var2=2\">my link</a>}
258
+ end
259
+
246
260
  protected
247
261
  def assert_sanitized(input, expected = nil)
248
262
  @sanitizer ||= HTML::WhiteListSanitizer.new
@@ -1,5 +1,6 @@
1
1
  require 'abstract_unit'
2
2
  require 'action_controller/integration'
3
+ require 'action_controller/routing'
3
4
 
4
5
  uses_mocha 'integration' do
5
6
 
@@ -12,12 +13,12 @@ end
12
13
 
13
14
  class SessionTest < Test::Unit::TestCase
14
15
  include IntegrationSessionStubbing
15
-
16
+
16
17
  def setup
17
18
  @session = ActionController::Integration::Session.new
18
19
  stub_integration_session(@session)
19
20
  end
20
-
21
+
21
22
  def test_https_bang_works_and_sets_truth_by_default
22
23
  assert !@session.https?
23
24
  @session.https!
@@ -196,7 +197,7 @@ class SessionTest < Test::Unit::TestCase
196
197
  @session.expects(:process).with(:head,path,params,headers_after_xhr)
197
198
  @session.xml_http_request(:head,path,params,headers)
198
199
  end
199
-
200
+
200
201
  def test_xml_http_request_override_accept
201
202
  path = "/index"; params = "blah"; headers = {:location => 'blah', "Accept" => "application/xml"}
202
203
  headers_after_xhr = headers.merge(
@@ -227,7 +228,6 @@ class IntegrationTestTest < Test::Unit::TestCase
227
228
  assert_equal ::ActionController::Integration::Session, session2.class
228
229
  assert_not_equal session1, session2
229
230
  end
230
-
231
231
  end
232
232
 
233
233
  # Tests that integration tests don't call Controller test methods for processing.
@@ -243,10 +243,171 @@ class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
243
243
  reset!
244
244
  stub_integration_session(@integration_session)
245
245
  %w( get post head put delete ).each do |verb|
246
- assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') }
246
+ assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') }
247
247
  end
248
248
  end
249
+ end
250
+
251
+ class IntegrationProcessTest < ActionController::IntegrationTest
252
+ class IntegrationController < ActionController::Base
253
+ session :off
254
+
255
+ def get
256
+ respond_to do |format|
257
+ format.html { render :text => "OK", :status => 200 }
258
+ format.js { render :text => "JS OK", :status => 200 }
259
+ end
260
+ end
261
+
262
+ def get_with_params
263
+ render :text => "foo: #{params[:foo]}", :status => 200
264
+ end
265
+
266
+ def post
267
+ render :text => "Created", :status => 201
268
+ end
249
269
 
270
+ def cookie_monster
271
+ cookies["cookie_1"] = nil
272
+ cookies["cookie_3"] = "chocolate"
273
+ render :text => "Gone", :status => 410
274
+ end
275
+
276
+ def redirect
277
+ redirect_to :action => "get"
278
+ end
279
+ end
280
+
281
+ def test_get
282
+ with_test_route_set do
283
+ get '/get'
284
+ assert_equal 200, status
285
+ assert_equal "OK", status_message
286
+ assert_equal "200 OK", response.headers["Status"]
287
+ assert_equal ["200 OK"], headers["status"]
288
+ assert_response 200
289
+ assert_response :success
290
+ assert_response :ok
291
+ assert_equal [], response.headers["cookie"]
292
+ assert_equal [], headers["cookie"]
293
+ assert_equal({}, cookies)
294
+ assert_equal "OK", response.body
295
+ assert_kind_of HTML::Document, html_document
296
+ assert_equal 1, request_count
297
+ end
298
+ end
299
+
300
+ def test_post
301
+ with_test_route_set do
302
+ post '/post'
303
+ assert_equal 201, status
304
+ assert_equal "Created", status_message
305
+ assert_equal "201 Created", response.headers["Status"]
306
+ assert_equal ["201 Created"], headers["status"]
307
+ assert_response 201
308
+ assert_response :success
309
+ assert_response :created
310
+ assert_equal [], response.headers["cookie"]
311
+ assert_equal [], headers["cookie"]
312
+ assert_equal({}, cookies)
313
+ assert_equal "Created", response.body
314
+ assert_kind_of HTML::Document, html_document
315
+ assert_equal 1, request_count
316
+ end
317
+ end
318
+
319
+ def test_cookie_monster
320
+ with_test_route_set do
321
+ self.cookies['cookie_1'] = "sugar"
322
+ self.cookies['cookie_2'] = "oatmeal"
323
+ get '/cookie_monster'
324
+ assert_equal 410, status
325
+ assert_equal "Gone", status_message
326
+ assert_equal "410 Gone", response.headers["Status"]
327
+ assert_equal ["410 Gone"], headers["status"]
328
+ assert_response 410
329
+ assert_response :gone
330
+ assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], response.headers["Set-Cookie"]
331
+ assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers['set-cookie']
332
+ assert_equal [
333
+ CGI::Cookie::new("name" => "cookie_1", "value" => ""),
334
+ CGI::Cookie::new("name" => "cookie_3", "value" => "chocolate")
335
+ ], response.headers["cookie"]
336
+ assert_equal [], headers["cookie"]
337
+ assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
338
+ assert_equal "Gone", response.body
339
+ end
340
+ end
341
+
342
+ def test_redirect
343
+ with_test_route_set do
344
+ get '/redirect'
345
+ assert_equal 302, status
346
+ assert_equal "Found", status_message
347
+ assert_equal "302 Found", response.headers["Status"]
348
+ assert_equal ["302 Found"], headers["status"]
349
+ assert_response 302
350
+ assert_response :redirect
351
+ assert_response :found
352
+ assert_equal "<html><body>You are being <a href=\"http://www.example.com/get\">redirected</a>.</body></html>", response.body
353
+ assert_kind_of HTML::Document, html_document
354
+ assert_equal 1, request_count
355
+ end
356
+ end
357
+
358
+ def test_xml_http_request_get
359
+ with_test_route_set do
360
+ xhr :get, '/get'
361
+ assert_equal 200, status
362
+ assert_equal "OK", status_message
363
+ assert_equal "200 OK", response.headers["Status"]
364
+ assert_equal ["200 OK"], headers["status"]
365
+ assert_response 200
366
+ assert_response :success
367
+ assert_response :ok
368
+ assert_equal "JS OK", response.body
369
+ end
370
+ end
371
+
372
+ def test_get_with_query_string
373
+ with_test_route_set do
374
+ get '/get_with_params?foo=bar'
375
+ assert_equal '/get_with_params?foo=bar', request.env["REQUEST_URI"]
376
+ assert_equal '/get_with_params?foo=bar', request.request_uri
377
+ assert_equal nil, request.env["QUERY_STRING"]
378
+ assert_equal 'foo=bar', request.query_string
379
+ assert_equal 'bar', request.parameters['foo']
380
+
381
+ assert_equal 200, status
382
+ assert_equal "foo: bar", response.body
383
+ end
384
+ end
385
+
386
+ def test_get_with_parameters
387
+ with_test_route_set do
388
+ get '/get_with_params', :foo => "bar"
389
+ assert_equal '/get_with_params', request.env["REQUEST_URI"]
390
+ assert_equal '/get_with_params', request.request_uri
391
+ assert_equal 'foo=bar', request.env["QUERY_STRING"]
392
+ assert_equal 'foo=bar', request.query_string
393
+ assert_equal 'bar', request.parameters['foo']
394
+
395
+ assert_equal 200, status
396
+ assert_equal "foo: bar", response.body
397
+ end
398
+ end
399
+
400
+ private
401
+ def with_test_route_set
402
+ with_routing do |set|
403
+ set.draw do |map|
404
+ map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
405
+ c.connect "/:action"
406
+ end
407
+ end
408
+ yield
409
+ end
410
+ end
250
411
  end
251
412
 
252
- end # uses_mocha
413
+ end
@@ -31,16 +31,8 @@ end
31
31
  class MultipleExtensions < LayoutTest
32
32
  end
33
33
 
34
- class MabView < ActionView::TemplateHandler
35
- def initialize(view)
36
- end
37
-
38
- def render(template)
39
- template.source
40
- end
41
- end
42
-
43
- ActionView::Template::register_template_handler :mab, MabView
34
+ ActionView::Template::register_template_handler :mab,
35
+ lambda { |template| template.source.inspect }
44
36
 
45
37
  class LayoutAutoDiscoveryTest < Test::Unit::TestCase
46
38
  def setup
@@ -49,20 +41,21 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
49
41
 
50
42
  @request.host = "www.nextangle.com"
51
43
  end
52
-
44
+
53
45
  def test_application_layout_is_default_when_no_controller_match
54
46
  @controller = ProductController.new
55
47
  get :hello
56
48
  assert_equal 'layout_test.rhtml hello.rhtml', @response.body
57
49
  end
58
-
50
+
59
51
  def test_controller_name_layout_name_match
60
52
  @controller = ItemController.new
61
53
  get :hello
62
54
  assert_equal 'item.rhtml hello.rhtml', @response.body
63
55
  end
64
-
56
+
65
57
  def test_third_party_template_library_auto_discovers_layout
58
+ ThirdPartyTemplateLibraryController.view_paths.reload!
66
59
  @controller = ThirdPartyTemplateLibraryController.new
67
60
  get :hello
68
61
  assert_equal 'layouts/third_party_template_library', @controller.active_layout
@@ -70,14 +63,14 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
70
63
  assert_response :success
71
64
  assert_equal 'Mab', @response.body
72
65
  end
73
-
66
+
74
67
  def test_namespaced_controllers_auto_detect_layouts
75
68
  @controller = ControllerNameSpace::NestedController.new
76
69
  get :hello
77
70
  assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
78
71
  assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
79
72
  end
80
-
73
+
81
74
  def test_namespaced_controllers_auto_detect_layouts
82
75
  @controller = MultipleExtensions.new
83
76
  get :hello
@@ -86,53 +79,6 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
86
79
  end
87
80
  end
88
81
 
89
- class ExemptFromLayoutTest < Test::Unit::TestCase
90
- def setup
91
- @controller = LayoutTest.new
92
- @request = ActionController::TestRequest.new
93
- @response = ActionController::TestResponse.new
94
- end
95
-
96
- def test_rjs_exempt_from_layout
97
- assert @controller.send!(:template_exempt_from_layout?, 'test.rjs')
98
- end
99
-
100
- def test_rhtml_and_rxml_not_exempt_from_layout
101
- assert !@controller.send!(:template_exempt_from_layout?, 'test.rhtml')
102
- assert !@controller.send!(:template_exempt_from_layout?, 'test.rxml')
103
- end
104
-
105
- def test_other_extension_not_exempt_from_layout
106
- assert !@controller.send!(:template_exempt_from_layout?, 'test.random')
107
- end
108
-
109
- def test_add_extension_to_exempt_from_layout
110
- ['rpdf', :rpdf].each do |ext|
111
- assert_nothing_raised do
112
- ActionController::Base.exempt_from_layout ext
113
- end
114
- assert @controller.send!(:template_exempt_from_layout?, "test.#{ext}")
115
- end
116
- end
117
-
118
- def test_add_regexp_to_exempt_from_layout
119
- ActionController::Base.exempt_from_layout /\.rdoc/
120
- assert @controller.send!(:template_exempt_from_layout?, 'test.rdoc')
121
- end
122
-
123
- def test_rhtml_exempt_from_layout_status_should_prevent_layout_render
124
- ActionController::Base.exempt_from_layout :rhtml
125
-
126
- assert @controller.send!(:template_exempt_from_layout?, 'test.rhtml')
127
- assert @controller.send!(:template_exempt_from_layout?, 'hello.rhtml')
128
-
129
- get :hello
130
- assert_equal 'hello.rhtml', @response.body
131
- ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
132
- end
133
- end
134
-
135
-
136
82
  class DefaultLayoutController < LayoutTest
137
83
  end
138
84
 
@@ -163,19 +109,19 @@ class LayoutSetInResponseTest < Test::Unit::TestCase
163
109
  get :hello
164
110
  assert_equal 'layouts/layout_test', @response.layout
165
111
  end
166
-
112
+
167
113
  def test_layout_set_when_set_in_controller
168
114
  @controller = HasOwnLayoutController.new
169
115
  get :hello
170
116
  assert_equal 'layouts/item', @response.layout
171
117
  end
172
-
118
+
173
119
  def test_layout_set_when_using_render
174
120
  @controller = SetsLayoutInRenderController.new
175
121
  get :hello
176
122
  assert_equal 'layouts/third_party_template_library', @response.layout
177
123
  end
178
-
124
+
179
125
  def test_layout_is_not_set_when_none_rendered
180
126
  @controller = RendersNoLayoutController.new
181
127
  get :hello
@@ -186,8 +132,6 @@ class LayoutSetInResponseTest < Test::Unit::TestCase
186
132
  ActionController::Base.exempt_from_layout :rhtml
187
133
  @controller = RenderWithTemplateOptionController.new
188
134
 
189
- assert @controller.send(:template_exempt_from_layout?, 'alt/hello.rhtml')
190
-
191
135
  get :hello
192
136
  assert_equal "alt/hello.rhtml", @response.body.strip
193
137
 
@@ -256,4 +200,3 @@ class LayoutSymlinkedIsRenderedTest < Test::Unit::TestCase
256
200
  assert_equal "layouts/symlinked/symlinked_layout", @response.layout
257
201
  end
258
202
  end
259
-