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.
- data/CHANGELOG +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- 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 :
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
245
|
+
controller.instance_variable_set(:"@before_ran", true)
|
246
246
|
end
|
247
247
|
|
248
248
|
def after(controller)
|
249
|
-
controller.
|
250
|
-
controller.
|
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.
|
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.
|
729
|
+
c.instance_variable_set(:"@before", true)
|
730
730
|
b.call
|
731
|
-
c.
|
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>]]>", "<![CDATA[<span>section</span>]]>"
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_should_sanitize_unterminated_cdata_section
|
253
|
+
assert_sanitized "<![CDATA[<span>neverending...", "<![CDATA[<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&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") {
|
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
|
413
|
+
end
|
@@ -31,16 +31,8 @@ end
|
|
31
31
|
class MultipleExtensions < LayoutTest
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
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
|
-
|