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.
- data/CHANGELOG +149 -7
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +5 -6
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions/model_assertions.rb +2 -1
- data/lib/action_controller/assertions/response_assertions.rb +4 -2
- data/lib/action_controller/assertions/routing_assertions.rb +3 -3
- data/lib/action_controller/assertions/selector_assertions.rb +30 -27
- data/lib/action_controller/assertions/tag_assertions.rb +3 -3
- data/lib/action_controller/base.rb +103 -129
- data/lib/action_controller/benchmarking.rb +3 -3
- data/lib/action_controller/caching.rb +41 -652
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext/cookie.rb +27 -23
- data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
- data/lib/action_controller/cgi_process.rb +6 -4
- data/lib/action_controller/components.rb +7 -6
- data/lib/action_controller/cookies.rb +31 -19
- data/lib/action_controller/dispatcher.rb +51 -84
- data/lib/action_controller/filters.rb +295 -421
- data/lib/action_controller/flash.rb +1 -6
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +26 -9
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +65 -13
- data/lib/action_controller/layout.rb +24 -39
- data/lib/action_controller/mime_responds.rb +7 -3
- data/lib/action_controller/mime_type.rb +25 -9
- data/lib/action_controller/mime_types.rb +1 -1
- data/lib/action_controller/polymorphic_routes.rb +32 -17
- data/lib/action_controller/record_identifier.rb +10 -4
- data/lib/action_controller/request.rb +46 -30
- data/lib/action_controller/request_forgery_protection.rb +10 -9
- data/lib/action_controller/request_profiler.rb +29 -8
- data/lib/action_controller/rescue.rb +24 -24
- data/lib/action_controller/resources.rb +66 -23
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing.rb +113 -1229
- data/lib/action_controller/routing/builder.rb +204 -0
- data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
- data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +435 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +13 -8
- data/lib/action_controller/session/cookie_store.rb +20 -17
- data/lib/action_controller/session_management.rb +10 -3
- data/lib/action_controller/streaming.rb +45 -31
- data/lib/action_controller/test_case.rb +33 -23
- data/lib/action_controller/test_process.rb +39 -35
- data/lib/action_controller/url_rewriter.rb +18 -12
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +11 -3
- data/lib/action_view/base.rb +73 -390
- data/lib/action_view/helpers/active_record_helper.rb +83 -62
- data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
- data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
- data/lib/action_view/helpers/benchmark_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +3 -2
- data/lib/action_view/helpers/capture_helper.rb +1 -2
- data/lib/action_view/helpers/date_helper.rb +104 -82
- data/lib/action_view/helpers/form_helper.rb +148 -75
- data/lib/action_view/helpers/form_options_helper.rb +44 -23
- data/lib/action_view/helpers/form_tag_helper.rb +22 -13
- data/lib/action_view/helpers/javascripts/controls.js +1 -1
- data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
- data/lib/action_view/helpers/javascripts/effects.js +1 -1
- data/lib/action_view/helpers/number_helper.rb +10 -3
- data/lib/action_view/helpers/prototype_helper.rb +61 -29
- data/lib/action_view/helpers/record_tag_helper.rb +3 -3
- data/lib/action_view/helpers/sanitize_helper.rb +23 -17
- data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
- data/lib/action_view/helpers/text_helper.rb +153 -125
- data/lib/action_view/helpers/url_helper.rb +83 -28
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +31 -73
- data/lib/action_view/template.rb +127 -0
- data/lib/action_view/template_error.rb +8 -7
- data/lib/action_view/template_finder.rb +177 -0
- data/lib/action_view/template_handler.rb +18 -1
- data/lib/action_view/template_handlers/builder.rb +10 -2
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +37 -2
- data/lib/action_view/template_handlers/rjs.rb +14 -1
- data/lib/action_view/test_case.rb +58 -0
- data/test/abstract_unit.rb +1 -1
- data/test/active_record_unit.rb +3 -6
- data/test/activerecord/active_record_store_test.rb +1 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +16 -19
- data/test/controller/addresses_render_test.rb +1 -1
- data/test/controller/assert_select_test.rb +13 -6
- data/test/controller/base_test.rb +48 -2
- data/test/controller/benchmark_test.rb +1 -2
- data/test/controller/caching_test.rb +282 -21
- data/test/controller/capture_test.rb +1 -1
- data/test/controller/cgi_test.rb +1 -1
- data/test/controller/components_test.rb +1 -1
- data/test/controller/content_type_test.rb +2 -2
- data/test/controller/cookie_test.rb +13 -2
- data/test/controller/custom_handler_test.rb +14 -10
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
- data/test/controller/dispatcher_test.rb +31 -49
- data/test/controller/fake_controllers.rb +17 -0
- data/test/controller/fake_models.rb +6 -0
- data/test/controller/filter_params_test.rb +14 -8
- data/test/controller/filters_test.rb +44 -16
- data/test/controller/flash_test.rb +2 -2
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +19 -15
- data/test/controller/html-scanner/document_test.rb +1 -2
- data/test/controller/html-scanner/node_test.rb +1 -2
- data/test/controller/html-scanner/sanitizer_test.rb +8 -5
- data/test/controller/html-scanner/tag_node_test.rb +1 -2
- data/test/controller/html-scanner/text_node_test.rb +2 -3
- data/test/controller/html-scanner/tokenizer_test.rb +8 -2
- data/test/controller/http_authentication_test.rb +1 -1
- data/test/controller/integration_test.rb +14 -16
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +26 -6
- data/test/controller/mime_responds_test.rb +39 -7
- data/test/controller/mime_type_test.rb +29 -5
- data/test/controller/new_render_test.rb +105 -34
- data/test/controller/polymorphic_routes_test.rb +32 -20
- data/test/controller/record_identifier_test.rb +38 -2
- data/test/controller/redirect_test.rb +21 -1
- data/test/controller/render_test.rb +59 -15
- data/test/controller/request_forgery_protection_test.rb +92 -5
- data/test/controller/request_test.rb +64 -6
- data/test/controller/rescue_test.rb +22 -6
- data/test/controller/resources_test.rb +102 -14
- data/test/controller/routing_test.rb +231 -19
- data/test/controller/selector_test.rb +2 -2
- data/test/controller/send_file_test.rb +14 -3
- data/test/controller/session/cookie_store_test.rb +16 -4
- data/test/controller/session/mem_cache_store_test.rb +3 -4
- data/test/controller/session_fixation_test.rb +1 -1
- data/test/controller/session_management_test.rb +23 -1
- data/test/controller/test_test.rb +39 -18
- data/test/controller/url_rewriter_test.rb +35 -1
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -12
- data/test/controller/webservice_test.rb +48 -3
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/company.rb +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/controls.js +1 -0
- data/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/test/fixtures/public/javascripts/effects.js +1 -0
- data/test/fixtures/public/javascripts/prototype.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/reply.rb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +25 -8
- data/test/template/asset_tag_helper_test.rb +100 -17
- data/test/template/atom_feed_helper_test.rb +29 -1
- data/test/template/benchmark_helper_test.rb +10 -22
- data/test/template/date_helper_test.rb +455 -153
- data/test/template/erb_util_test.rb +10 -42
- data/test/template/form_helper_test.rb +192 -66
- data/test/template/form_options_helper_test.rb +19 -8
- data/test/template/form_tag_helper_test.rb +11 -8
- data/test/template/javascript_helper_test.rb +3 -9
- data/test/template/number_helper_test.rb +6 -3
- data/test/template/prototype_helper_test.rb +27 -40
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +5 -6
- data/test/template/scriptaculous_helper_test.rb +7 -13
- data/test/template/tag_helper_test.rb +3 -6
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +46 -33
- data/test/template/url_helper_test.rb +8 -10
- metadata +65 -12
- data/lib/action_view/compiled_templates.rb +0 -69
- data/test/action_view_test.rb +0 -44
- data/test/activerecord/fixtures_test.rb +0 -24
- data/test/controller/fragment_store_setting_test.rb +0 -47
- data/test/template/compiled_templates_test.rb +0 -197
- data/test/template/deprecate_ivars_test.rb +0 -51
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
class FlashTest < Test::Unit::TestCase
|
4
4
|
class TestController < ActionController::Base
|
@@ -52,7 +52,7 @@ class FlashTest < Test::Unit::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def rescue_action(e)
|
55
|
-
raise unless
|
55
|
+
raise unless ActionView::MissingTemplate === e
|
56
56
|
end
|
57
57
|
|
58
58
|
# methods for test_sweep_after_halted_filter_chain
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class HeaderTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@headers = ActionController::Http::Headers.new("HTTP_CONTENT_TYPE"=>"text/plain")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_content_type_works
|
9
|
+
assert_equal "text/plain", @headers["Content-Type"]
|
10
|
+
assert_equal "text/plain", @headers["content-type"]
|
11
|
+
assert_equal "text/plain", @headers["CONTENT_TYPE"]
|
12
|
+
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
|
13
|
+
end
|
14
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
ActionController::Helpers::HELPERS_DIR.replace File.dirname(__FILE__) + '/../fixtures/helpers'
|
4
4
|
|
@@ -46,22 +46,10 @@ class HelperTest < Test::Unit::TestCase
|
|
46
46
|
eval("class #{controller_class_name} < TestController; end")
|
47
47
|
@controller_class = self.class.const_get(controller_class_name)
|
48
48
|
|
49
|
-
# Generate new template class and assign to controller.
|
50
|
-
template_class_name = "Test#{@symbol}View"
|
51
|
-
eval("class #{template_class_name} < ActionView::Base; end")
|
52
|
-
@template_class = self.class.const_get(template_class_name)
|
53
|
-
@controller_class.template_class = @template_class
|
54
|
-
|
55
49
|
# Set default test helper.
|
56
50
|
self.test_helper = LocalAbcHelper
|
57
51
|
end
|
58
|
-
|
59
|
-
def teardown
|
60
|
-
# Reset template class.
|
61
|
-
#ActionController::Base.template_class = ActionView::Base
|
62
|
-
end
|
63
|
-
|
64
|
-
|
52
|
+
|
65
53
|
def test_deprecated_helper
|
66
54
|
assert_equal expected_helper_methods, missing_methods
|
67
55
|
assert_nothing_raised { @controller_class.helper TestHelper }
|
@@ -97,7 +85,7 @@ class HelperTest < Test::Unit::TestCase
|
|
97
85
|
def test_helper_block_include
|
98
86
|
assert_equal expected_helper_methods, missing_methods
|
99
87
|
assert_nothing_raised {
|
100
|
-
@controller_class.helper { include TestHelper }
|
88
|
+
@controller_class.helper { include HelperTest::TestHelper }
|
101
89
|
}
|
102
90
|
assert [], missing_methods
|
103
91
|
end
|
@@ -142,6 +130,22 @@ class HelperTest < Test::Unit::TestCase
|
|
142
130
|
assert methods.include?('foobar')
|
143
131
|
end
|
144
132
|
|
133
|
+
def test_helper_proxy
|
134
|
+
methods = ApplicationController.helpers.methods.map(&:to_s)
|
135
|
+
|
136
|
+
# ActionView
|
137
|
+
assert methods.include?('pluralize')
|
138
|
+
|
139
|
+
# abc_helper.rb
|
140
|
+
assert methods.include?('bare_a')
|
141
|
+
|
142
|
+
# fun/games_helper.rb
|
143
|
+
assert methods.include?('stratego')
|
144
|
+
|
145
|
+
# fun/pdf_helper.rb
|
146
|
+
assert methods.include?('foobar')
|
147
|
+
end
|
148
|
+
|
145
149
|
private
|
146
150
|
def expected_helper_methods
|
147
151
|
TestHelper.instance_methods.map(&:to_s)
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'test/unit'
|
1
|
+
require 'abstract_unit'
|
3
2
|
|
4
3
|
class SanitizerTest < Test::Unit::TestCase
|
5
4
|
def setup
|
@@ -241,15 +240,19 @@ class SanitizerTest < Test::Unit::TestCase
|
|
241
240
|
end
|
242
241
|
|
243
242
|
def test_should_sanitize_img_vbscript
|
244
|
-
|
243
|
+
assert_sanitized %(<img src='vbscript:msgbox("XSS")' />), '<img />'
|
245
244
|
end
|
246
245
|
|
247
246
|
protected
|
248
247
|
def assert_sanitized(input, expected = nil)
|
249
248
|
@sanitizer ||= HTML::WhiteListSanitizer.new
|
250
|
-
|
249
|
+
if input
|
250
|
+
assert_dom_equal expected || input, @sanitizer.sanitize(input)
|
251
|
+
else
|
252
|
+
assert_nil @sanitizer.sanitize(input)
|
253
|
+
end
|
251
254
|
end
|
252
|
-
|
255
|
+
|
253
256
|
def sanitize_css(input)
|
254
257
|
(@sanitizer ||= HTML::WhiteListSanitizer.new).sanitize_css(input)
|
255
258
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'test/unit'
|
1
|
+
require 'abstract_unit'
|
3
2
|
|
4
3
|
class TextNodeTest < Test::Unit::TestCase
|
5
4
|
def setup
|
@@ -48,4 +47,4 @@ class TextNodeTest < Test::Unit::TestCase
|
|
48
47
|
def test_match_other
|
49
48
|
assert_nil @node.match(:hello)
|
50
49
|
end
|
51
|
-
end
|
50
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'test/unit'
|
1
|
+
require 'abstract_unit'
|
3
2
|
|
4
3
|
class TokenizerTest < Test::Unit::TestCase
|
5
4
|
|
@@ -79,6 +78,13 @@ class TokenizerTest < Test::Unit::TestCase
|
|
79
78
|
assert_end
|
80
79
|
end
|
81
80
|
|
81
|
+
def test_unterminated_cdata_tag
|
82
|
+
tokenize %{<content:encoded><![CDATA[ neverending...}
|
83
|
+
assert_next %{<content:encoded>}
|
84
|
+
assert_next %{<![CDATA[ neverending...}
|
85
|
+
assert_end
|
86
|
+
end
|
87
|
+
|
82
88
|
def test_less_than_with_space
|
83
89
|
tokenize %{original < hello > world}
|
84
90
|
assert_next %{original }
|
@@ -1,26 +1,23 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'abstract_unit'
|
3
2
|
require 'action_controller/integration'
|
4
3
|
|
5
4
|
uses_mocha 'integration' do
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def process(*args)
|
12
|
-
end
|
13
|
-
|
14
|
-
def generic_url_rewriter
|
15
|
-
end
|
16
|
-
end
|
6
|
+
module IntegrationSessionStubbing
|
7
|
+
def stub_integration_session(session)
|
8
|
+
session.stubs(:process)
|
9
|
+
session.stubs(:generic_url_rewriter)
|
17
10
|
end
|
18
11
|
end
|
19
12
|
|
20
13
|
class SessionTest < Test::Unit::TestCase
|
14
|
+
include IntegrationSessionStubbing
|
15
|
+
|
21
16
|
def setup
|
22
17
|
@session = ActionController::Integration::Session.new
|
18
|
+
stub_integration_session(@session)
|
23
19
|
end
|
20
|
+
|
24
21
|
def test_https_bang_works_and_sets_truth_by_default
|
25
22
|
assert !@session.https?
|
26
23
|
@session.https!
|
@@ -211,11 +208,13 @@ class SessionTest < Test::Unit::TestCase
|
|
211
208
|
end
|
212
209
|
|
213
210
|
class IntegrationTestTest < Test::Unit::TestCase
|
211
|
+
include IntegrationSessionStubbing
|
214
212
|
|
215
213
|
def setup
|
216
214
|
@test = ::ActionController::IntegrationTest.new(:default_test)
|
217
215
|
@test.class.stubs(:fixture_table_names).returns([])
|
218
216
|
@session = @test.open_session
|
217
|
+
stub_integration_session(@session)
|
219
218
|
end
|
220
219
|
|
221
220
|
def test_opens_new_session
|
@@ -234,12 +233,15 @@ end
|
|
234
233
|
# Tests that integration tests don't call Controller test methods for processing.
|
235
234
|
# Integration tests have their own setup and teardown.
|
236
235
|
class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
|
236
|
+
include IntegrationSessionStubbing
|
237
237
|
|
238
238
|
def self.fixture_table_names
|
239
239
|
[]
|
240
240
|
end
|
241
241
|
|
242
242
|
def test_integration_methods_called
|
243
|
+
reset!
|
244
|
+
stub_integration_session(@integration_session)
|
243
245
|
%w( get post head put delete ).each do |verb|
|
244
246
|
assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') }
|
245
247
|
end
|
@@ -247,8 +249,4 @@ class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
|
|
247
249
|
|
248
250
|
end
|
249
251
|
|
250
|
-
# TODO
|
251
|
-
# class MockCGITest < Test::Unit::TestCase
|
252
|
-
# end
|
253
|
-
|
254
252
|
end # uses_mocha
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'action_controller/integration'
|
3
|
+
require 'action_controller/routing'
|
4
|
+
|
5
|
+
unless defined? ApplicationController
|
6
|
+
class ApplicationController < ActionController::Base
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class UploadTestController < ActionController::Base
|
11
|
+
session :off
|
12
|
+
|
13
|
+
def update
|
14
|
+
SessionUploadTest.last_request_type = ActionController::Base.param_parsers[request.content_type]
|
15
|
+
render :text => "got here"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class SessionUploadTest < ActionController::IntegrationTest
|
20
|
+
FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
attr_accessor :last_request_type
|
24
|
+
end
|
25
|
+
|
26
|
+
# def setup
|
27
|
+
# @session = ActionController::Integration::Session.new
|
28
|
+
# end
|
29
|
+
def test_post_with_upload
|
30
|
+
uses_mocha "test_post_with_upload" do
|
31
|
+
Dependencies.stubs(:load?).returns(false)
|
32
|
+
with_routing do |set|
|
33
|
+
set.draw do |map|
|
34
|
+
map.update 'update', :controller => "upload_test", :action => "update", :method => :post
|
35
|
+
end
|
36
|
+
|
37
|
+
params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") }
|
38
|
+
post '/update', params, :location => 'blah'
|
39
|
+
assert_equal(:multipart_form, SessionUploadTest.last_request_type)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
# The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
|
4
4
|
# method has access to the view_paths array when looking for a layout to automatically assign.
|
@@ -31,16 +31,16 @@ end
|
|
31
31
|
class MultipleExtensions < LayoutTest
|
32
32
|
end
|
33
33
|
|
34
|
-
class MabView
|
34
|
+
class MabView < ActionView::TemplateHandler
|
35
35
|
def initialize(view)
|
36
36
|
end
|
37
37
|
|
38
|
-
def render(
|
39
|
-
|
38
|
+
def render(template)
|
39
|
+
template.source
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
ActionView::
|
43
|
+
ActionView::Template::register_template_handler :mab, MabView
|
44
44
|
|
45
45
|
class LayoutAutoDiscoveryTest < Test::Unit::TestCase
|
46
46
|
def setup
|
@@ -67,6 +67,7 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
|
|
67
67
|
get :hello
|
68
68
|
assert_equal 'layouts/third_party_template_library', @controller.active_layout
|
69
69
|
assert_equal 'layouts/third_party_template_library', @response.layout
|
70
|
+
assert_response :success
|
70
71
|
assert_equal 'Mab', @response.body
|
71
72
|
end
|
72
73
|
|
@@ -215,7 +216,7 @@ class LayoutExceptionRaised < Test::Unit::TestCase
|
|
215
216
|
@controller = SetsNonExistentLayoutFile.new
|
216
217
|
get :hello
|
217
218
|
@response.template.class.module_eval { attr_accessor :exception }
|
218
|
-
assert_equal
|
219
|
+
assert_equal ActionView::MissingTemplate, @response.template.exception.class
|
219
220
|
end
|
220
221
|
end
|
221
222
|
|
@@ -237,3 +238,22 @@ class LayoutStatusIsRenderedTest < Test::Unit::TestCase
|
|
237
238
|
assert_response 401
|
238
239
|
end
|
239
240
|
end
|
241
|
+
|
242
|
+
class LayoutSymlinkedTest < LayoutTest
|
243
|
+
layout "symlinked/symlinked_layout"
|
244
|
+
end
|
245
|
+
|
246
|
+
class LayoutSymlinkedIsRenderedTest < Test::Unit::TestCase
|
247
|
+
def setup
|
248
|
+
@request = ActionController::TestRequest.new
|
249
|
+
@response = ActionController::TestResponse.new
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_symlinked_layout_is_rendered
|
253
|
+
@controller = LayoutSymlinkedTest.new
|
254
|
+
get :hello
|
255
|
+
assert_response 200
|
256
|
+
assert_equal "layouts/symlinked/symlinked_layout", @response.layout
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
class RespondToController < ActionController::Base
|
4
4
|
layout :set_layout
|
@@ -107,6 +107,13 @@ class RespondToController < ActionController::Base
|
|
107
107
|
type.any(:js, :xml) { render :text => "Either JS or XML" }
|
108
108
|
end
|
109
109
|
end
|
110
|
+
|
111
|
+
def handle_any_any
|
112
|
+
respond_to do |type|
|
113
|
+
type.html { render :text => 'HTML' }
|
114
|
+
type.any { render :text => 'Whatever you ask for, I got it' }
|
115
|
+
end
|
116
|
+
end
|
110
117
|
|
111
118
|
def all_types_with_layout
|
112
119
|
respond_to do |type|
|
@@ -335,6 +342,35 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
335
342
|
assert_equal 'Either JS or XML', @response.body
|
336
343
|
end
|
337
344
|
|
345
|
+
def test_handle_any_any
|
346
|
+
@request.env["HTTP_ACCEPT"] = "*/*"
|
347
|
+
get :handle_any_any
|
348
|
+
assert_equal 'HTML', @response.body
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_handle_any_any_parameter_format
|
352
|
+
get :handle_any_any, {:format=>'html'}
|
353
|
+
assert_equal 'HTML', @response.body
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_handle_any_any_explicit_html
|
357
|
+
@request.env["HTTP_ACCEPT"] = "text/html"
|
358
|
+
get :handle_any_any
|
359
|
+
assert_equal 'HTML', @response.body
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_handle_any_any_javascript
|
363
|
+
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
364
|
+
get :handle_any_any
|
365
|
+
assert_equal 'Whatever you ask for, I got it', @response.body
|
366
|
+
end
|
367
|
+
|
368
|
+
def test_handle_any_any_xml
|
369
|
+
@request.env["HTTP_ACCEPT"] = "text/xml"
|
370
|
+
get :handle_any_any
|
371
|
+
assert_equal 'Whatever you ask for, I got it', @response.body
|
372
|
+
end
|
373
|
+
|
338
374
|
def test_rjs_type_skips_layout
|
339
375
|
@request.env["HTTP_ACCEPT"] = "text/javascript"
|
340
376
|
get :all_types_with_layout
|
@@ -432,16 +468,12 @@ class MimeControllerTest < Test::Unit::TestCase
|
|
432
468
|
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
|
433
469
|
|
434
470
|
@request.env["HTTP_ACCEPT"] = "text/iphone"
|
435
|
-
assert_raises(
|
471
|
+
assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
|
436
472
|
end
|
437
473
|
end
|
438
474
|
|
439
475
|
class AbstractPostController < ActionController::Base
|
440
|
-
|
441
|
-
def view_paths
|
442
|
-
[ File.dirname(__FILE__) + "/../fixtures/post_test/" ]
|
443
|
-
end
|
444
|
-
end
|
476
|
+
self.view_paths = File.dirname(__FILE__) + "/../fixtures/post_test/"
|
445
477
|
end
|
446
478
|
|
447
479
|
# For testing layouts which are set automatically
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
class MimeTypeTest < Test::Unit::TestCase
|
4
4
|
Mime::Type.register "image/png", :png
|
@@ -28,6 +28,13 @@ class MimeTypeTest < Test::Unit::TestCase
|
|
28
28
|
expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
|
29
29
|
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
|
30
30
|
end
|
31
|
+
|
32
|
+
# Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
|
33
|
+
def test_parse_crappy_broken_acceptlines2
|
34
|
+
accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
|
35
|
+
expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ]
|
36
|
+
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
|
37
|
+
end
|
31
38
|
|
32
39
|
def test_custom_type
|
33
40
|
Mime::Type.register("image/gif", :gif)
|
@@ -45,16 +52,33 @@ class MimeTypeTest < Test::Unit::TestCase
|
|
45
52
|
end
|
46
53
|
|
47
54
|
def test_type_convenience_methods
|
48
|
-
|
55
|
+
# Don't test Mime::ALL, since it Mime::ALL#html? == true
|
56
|
+
types = Mime::SET.to_a.map(&:to_sym).uniq - [:all]
|
57
|
+
|
58
|
+
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
59
|
+
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
|
60
|
+
|
49
61
|
types.each do |type|
|
50
62
|
mime = Mime.const_get(type.to_s.upcase)
|
51
|
-
assert mime.send("#{type}?"), "
|
52
|
-
(types - [type]).each { |
|
63
|
+
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
|
64
|
+
(types - [type]).each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
|
53
65
|
end
|
54
66
|
end
|
55
|
-
|
67
|
+
|
56
68
|
def test_mime_all_is_html
|
57
69
|
assert Mime::ALL.all?, "Mime::ALL is not all?"
|
58
70
|
assert Mime::ALL.html?, "Mime::ALL is not html?"
|
59
71
|
end
|
72
|
+
|
73
|
+
def test_verifiable_mime_types
|
74
|
+
unverified_types = Mime::Type.unverifiable_types
|
75
|
+
all_types = Mime::SET.to_a.map(&:to_sym)
|
76
|
+
all_types.uniq!
|
77
|
+
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
|
78
|
+
all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
|
79
|
+
|
80
|
+
unverified, verified = all_types.partition { |type| Mime::Type.unverifiable_types.include? type }
|
81
|
+
assert verified.all? { |type| Mime.const_get(type.to_s.upcase).verify_request? }, "Not all Mime Types are verified: #{verified.inspect}"
|
82
|
+
assert unverified.all? { |type| !Mime.const_get(type.to_s.upcase).verify_request? }, "Some Mime Types are verified: #{unverified.inspect}"
|
83
|
+
end
|
60
84
|
end
|