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
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
|
3
|
-
|
4
3
|
module TestFileUtils
|
5
4
|
def file_name() File.basename(__FILE__) end
|
6
5
|
def file_path() File.expand_path(__FILE__) end
|
7
6
|
def file_data() File.open(file_path, 'rb') { |f| f.read } end
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
9
|
class SendFileController < ActionController::Base
|
12
10
|
include TestFileUtils
|
13
11
|
layout "layouts/standard" # to make sure layouts don't interfere
|
@@ -21,8 +19,6 @@ class SendFileController < ActionController::Base
|
|
21
19
|
def rescue_action(e) raise end
|
22
20
|
end
|
23
21
|
|
24
|
-
SendFileController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
25
|
-
|
26
22
|
class SendFileTest < Test::Unit::TestCase
|
27
23
|
include TestFileUtils
|
28
24
|
|
@@ -36,7 +36,9 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
36
36
|
'session_key' => '_myapp_session',
|
37
37
|
'secret' => 'Keep it secret; keep it safe.',
|
38
38
|
'no_cookies' => true,
|
39
|
-
'no_hidden' => true
|
39
|
+
'no_hidden' => true,
|
40
|
+
'session_http_only' => true
|
41
|
+
}
|
40
42
|
end
|
41
43
|
|
42
44
|
def self.cookies
|
@@ -149,6 +151,48 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
149
151
|
assert_equal 1, session.cgi.output_cookies.size
|
150
152
|
cookie = session.cgi.output_cookies.first
|
151
153
|
assert_cookie cookie, cookie_value(:flashed)
|
154
|
+
assert_http_only_cookie cookie
|
155
|
+
assert_secure_cookie cookie, false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_writes_non_secure_cookie_by_default
|
160
|
+
set_cookie! cookie_value(:typical)
|
161
|
+
new_session do |session|
|
162
|
+
session['flash'] = {}
|
163
|
+
session.close
|
164
|
+
cookie = session.cgi.output_cookies.first
|
165
|
+
assert_secure_cookie cookie,false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_writes_secure_cookie
|
170
|
+
set_cookie! cookie_value(:typical)
|
171
|
+
new_session('session_secure'=>true) do |session|
|
172
|
+
session['flash'] = {}
|
173
|
+
session.close
|
174
|
+
cookie = session.cgi.output_cookies.first
|
175
|
+
assert_secure_cookie cookie
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_http_only_cookie_by_default
|
180
|
+
set_cookie! cookie_value(:typical)
|
181
|
+
new_session do |session|
|
182
|
+
session['flash'] = {}
|
183
|
+
session.close
|
184
|
+
cookie = session.cgi.output_cookies.first
|
185
|
+
assert_http_only_cookie cookie
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_overides_http_only_cookie
|
190
|
+
set_cookie! cookie_value(:typical)
|
191
|
+
new_session('session_http_only'=>false) do |session|
|
192
|
+
session['flash'] = {}
|
193
|
+
session.close
|
194
|
+
cookie = session.cgi.output_cookies.first
|
195
|
+
assert_http_only_cookie cookie, false
|
152
196
|
end
|
153
197
|
end
|
154
198
|
|
@@ -195,6 +239,13 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
195
239
|
assert_equal expires, cookie.expires ? cookie.expires.to_date : cookie.expires, message
|
196
240
|
end
|
197
241
|
|
242
|
+
def assert_secure_cookie(cookie,value=true)
|
243
|
+
assert cookie.secure==value
|
244
|
+
end
|
245
|
+
|
246
|
+
def assert_http_only_cookie(cookie,value=true)
|
247
|
+
assert cookie.http_only==value
|
248
|
+
end
|
198
249
|
|
199
250
|
def cookies(*which)
|
200
251
|
self.class.cookies.values_at(*which)
|
@@ -215,6 +266,7 @@ class CookieStoreTest < Test::Unit::TestCase
|
|
215
266
|
|
216
267
|
@options = self.class.default_session_options.merge(options)
|
217
268
|
session = CGI::Session.new(cgi, @options)
|
269
|
+
ObjectSpace.undefine_finalizer(session)
|
218
270
|
|
219
271
|
assert_nil cgi.output_hidden, "Output hidden params should be empty: #{cgi.output_hidden.inspect}"
|
220
272
|
assert_nil cgi.output_cookies, "Output cookies should be empty: #{cgi.output_cookies.inspect}"
|
@@ -64,7 +64,7 @@ class TestTest < Test::Unit::TestCase
|
|
64
64
|
</html>
|
65
65
|
HTML
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def test_xml_output
|
69
69
|
response.content_type = "application/xml"
|
70
70
|
render :text => <<XML
|
@@ -117,8 +117,8 @@ XML
|
|
117
117
|
@controller = TestController.new
|
118
118
|
@request = ActionController::TestRequest.new
|
119
119
|
@response = ActionController::TestResponse.new
|
120
|
-
ActionController::Routing::Routes.reload
|
121
120
|
ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
|
121
|
+
ActionController::Routing::Routes.load_routes!
|
122
122
|
end
|
123
123
|
|
124
124
|
def teardown
|
@@ -366,7 +366,7 @@ XML
|
|
366
366
|
:children => { :count => 1,
|
367
367
|
:only => { :tag => "img" } } } }
|
368
368
|
end
|
369
|
-
|
369
|
+
|
370
370
|
def test_should_not_impose_childless_html_tags_in_xml
|
371
371
|
process :test_xml_output
|
372
372
|
|
@@ -412,7 +412,7 @@ XML
|
|
412
412
|
|
413
413
|
def test_assert_routing_with_method
|
414
414
|
with_routing do |set|
|
415
|
-
|
415
|
+
set.draw { |map| map.resources(:content) }
|
416
416
|
assert_routing({ :method => 'post', :path => 'content' }, { :controller => 'content', :action => 'create' })
|
417
417
|
end
|
418
418
|
end
|
@@ -486,7 +486,7 @@ XML
|
|
486
486
|
assert_nil @request.env['HTTP_X_REQUESTED_WITH']
|
487
487
|
end
|
488
488
|
|
489
|
-
|
489
|
+
def test_header_properly_reset_after_get_request
|
490
490
|
get :test_params
|
491
491
|
@request.recycle!
|
492
492
|
assert_nil @request.instance_variable_get("@request_method")
|
@@ -537,15 +537,15 @@ XML
|
|
537
537
|
assert_equal new_content_type, file.content_type
|
538
538
|
|
539
539
|
end
|
540
|
-
|
540
|
+
|
541
541
|
def test_test_uploaded_file_with_binary
|
542
542
|
filename = 'mona_lisa.jpg'
|
543
543
|
path = "#{FILES_DIR}/#{filename}"
|
544
544
|
content_type = 'image/png'
|
545
|
-
|
545
|
+
|
546
546
|
binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary)
|
547
547
|
assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read
|
548
|
-
|
548
|
+
|
549
549
|
plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type)
|
550
550
|
assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
|
551
551
|
end
|
@@ -554,10 +554,10 @@ XML
|
|
554
554
|
filename = 'mona_lisa.jpg'
|
555
555
|
path = "#{FILES_DIR}/#{filename}"
|
556
556
|
content_type = 'image/jpg'
|
557
|
-
|
557
|
+
|
558
558
|
binary_file_upload = fixture_file_upload(path, content_type, :binary)
|
559
559
|
assert_equal File.open(path, READ_BINARY).read, binary_file_upload.read
|
560
|
-
|
560
|
+
|
561
561
|
plain_file_upload = fixture_file_upload(path, content_type)
|
562
562
|
assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read
|
563
563
|
end
|
@@ -571,28 +571,6 @@ XML
|
|
571
571
|
assert_raise(RuntimeError) { ActionController::TestUploadedFile.new('non_existent_file') }
|
572
572
|
end
|
573
573
|
|
574
|
-
def test_assert_follow_redirect_to_same_controller
|
575
|
-
with_foo_routing do |set|
|
576
|
-
get :redirect_to_same_controller
|
577
|
-
assert_response :redirect
|
578
|
-
assert_redirected_to :controller => 'test_test/test', :action => 'test_uri', :id => 5
|
579
|
-
assert_deprecated 'follow_redirect' do
|
580
|
-
assert_nothing_raised { follow_redirect }
|
581
|
-
end
|
582
|
-
end
|
583
|
-
end
|
584
|
-
|
585
|
-
def test_assert_follow_redirect_to_different_controller
|
586
|
-
with_foo_routing do |set|
|
587
|
-
get :redirect_to_different_controller
|
588
|
-
assert_response :redirect
|
589
|
-
assert_redirected_to :controller => 'fail', :id => 5
|
590
|
-
assert_raise(RuntimeError) do
|
591
|
-
assert_deprecated { follow_redirect }
|
592
|
-
end
|
593
|
-
end
|
594
|
-
end
|
595
|
-
|
596
574
|
def test_redirect_url_only_cares_about_location_header
|
597
575
|
get :create
|
598
576
|
assert_response :created
|
@@ -611,7 +589,7 @@ XML
|
|
611
589
|
get :test_send_file
|
612
590
|
assert_nothing_raised(NoMethodError) { @response.binary_content }
|
613
591
|
end
|
614
|
-
|
592
|
+
|
615
593
|
protected
|
616
594
|
def with_foo_routing
|
617
595
|
with_routing do |set|
|
@@ -624,12 +602,11 @@ XML
|
|
624
602
|
end
|
625
603
|
end
|
626
604
|
|
627
|
-
|
628
605
|
class CleanBacktraceTest < Test::Unit::TestCase
|
629
606
|
def test_should_reraise_the_same_object
|
630
607
|
exception = Test::Unit::AssertionFailedError.new('message')
|
631
608
|
clean_backtrace { raise exception }
|
632
|
-
rescue => caught
|
609
|
+
rescue Exception => caught
|
633
610
|
assert_equal exception.object_id, caught.object_id
|
634
611
|
assert_equal exception.message, caught.message
|
635
612
|
end
|
@@ -639,7 +616,7 @@ class CleanBacktraceTest < Test::Unit::TestCase
|
|
639
616
|
exception = Test::Unit::AssertionFailedError.new('message')
|
640
617
|
exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
|
641
618
|
clean_backtrace { raise exception }
|
642
|
-
rescue => caught
|
619
|
+
rescue Exception => caught
|
643
620
|
assert_equal ["#{path}/abc"], caught.backtrace
|
644
621
|
end
|
645
622
|
|
@@ -685,11 +662,12 @@ end
|
|
685
662
|
|
686
663
|
class NamedRoutesControllerTest < ActionController::TestCase
|
687
664
|
tests ContentController
|
688
|
-
|
665
|
+
|
689
666
|
def test_should_be_able_to_use_named_routes_before_a_request_is_done
|
690
667
|
with_routing do |set|
|
691
668
|
set.draw { |map| map.resources :contents }
|
692
669
|
assert_equal 'http://test.host/contents/new', new_content_url
|
670
|
+
assert_equal 'http://test.host/contents/1', content_url(:id => 1)
|
693
671
|
end
|
694
672
|
end
|
695
673
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
# class TranslatingController < ActionController::Base
|
4
|
+
# end
|
5
|
+
|
6
|
+
class TranslationControllerTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@controller = ActionController::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_action_controller_base_responds_to_translate
|
12
|
+
assert @controller.respond_to?(:translate)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_action_controller_base_responds_to_t
|
16
|
+
assert @controller.respond_to?(:t)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_action_controller_base_responds_to_localize
|
20
|
+
assert @controller.respond_to?(:localize)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_action_controller_base_responds_to_l
|
24
|
+
assert @controller.respond_to?(:l)
|
25
|
+
end
|
26
|
+
end
|
@@ -7,7 +7,7 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|
7
7
|
@request = ActionController::TestRequest.new
|
8
8
|
@params = {}
|
9
9
|
@rewriter = ActionController::UrlRewriter.new(@request, @params)
|
10
|
-
end
|
10
|
+
end
|
11
11
|
|
12
12
|
def test_port
|
13
13
|
assert_equal('http://test.host:1271/c/a/i',
|
@@ -24,7 +24,7 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|
24
24
|
@rewriter.rewrite(:protocol => 'https://', :controller => 'c', :action => 'a', :id => 'i')
|
25
25
|
)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def test_user_name_and_password
|
29
29
|
assert_equal(
|
30
30
|
'http://david:secret@test.host/c/a/i',
|
@@ -38,12 +38,12 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|
38
38
|
@rewriter.rewrite(:user => "openid.aol.com/nextangler", :password => "one two?", :controller => 'c', :action => 'a', :id => 'i')
|
39
39
|
)
|
40
40
|
end
|
41
|
-
|
42
|
-
def test_anchor
|
43
|
-
assert_equal(
|
44
|
-
'http://test.host/c/a/i#anchor',
|
45
|
-
@rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor')
|
46
|
-
)
|
41
|
+
|
42
|
+
def test_anchor
|
43
|
+
assert_equal(
|
44
|
+
'http://test.host/c/a/i#anchor',
|
45
|
+
@rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => 'anchor')
|
46
|
+
)
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_overwrite_params
|
@@ -55,12 +55,12 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|
55
55
|
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'})
|
56
56
|
assert_match %r(/hi/hi/2$), u
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def test_overwrite_removes_original
|
60
60
|
@params[:controller] = 'search'
|
61
61
|
@params[:action] = 'list'
|
62
62
|
@params[:list_page] = 1
|
63
|
-
|
63
|
+
|
64
64
|
assert_equal '/search/list?list_page=2', @rewriter.rewrite(:only_path => true, :overwrite_params => {"list_page" => 2})
|
65
65
|
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2})
|
66
66
|
assert_equal 'http://test.host/search/list?list_page=2', u
|
@@ -86,19 +86,19 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|
86
86
|
end
|
87
87
|
|
88
88
|
class UrlWriterTests < Test::Unit::TestCase
|
89
|
-
|
89
|
+
|
90
90
|
class W
|
91
91
|
include ActionController::UrlWriter
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def teardown
|
95
95
|
W.default_url_options.clear
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def add_host!
|
99
99
|
W.default_url_options[:host] = 'www.basecamphq.com'
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def test_exception_is_thrown_without_host
|
103
103
|
assert_raises RuntimeError do
|
104
104
|
W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
|
@@ -110,35 +110,35 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
110
110
|
W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => 'anchor')
|
111
111
|
)
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
def test_default_host
|
115
115
|
add_host!
|
116
116
|
assert_equal('http://www.basecamphq.com/c/a/i',
|
117
117
|
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i')
|
118
118
|
)
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def test_host_may_be_overridden
|
122
122
|
add_host!
|
123
123
|
assert_equal('http://37signals.basecamphq.com/c/a/i',
|
124
124
|
W.new.url_for(:host => '37signals.basecamphq.com', :controller => 'c', :action => 'a', :id => 'i')
|
125
125
|
)
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def test_port
|
129
129
|
add_host!
|
130
130
|
assert_equal('http://www.basecamphq.com:3000/c/a/i',
|
131
131
|
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :port => 3000)
|
132
132
|
)
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
def test_protocol
|
136
136
|
add_host!
|
137
137
|
assert_equal('https://www.basecamphq.com/c/a/i',
|
138
138
|
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
139
139
|
)
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def test_protocol_with_and_without_separator
|
143
143
|
add_host!
|
144
144
|
assert_equal('https://www.basecamphq.com/c/a/i',
|
@@ -184,15 +184,15 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def test_relative_url_root_is_respected
|
187
|
-
orig_relative_url_root = ActionController::
|
188
|
-
ActionController::
|
187
|
+
orig_relative_url_root = ActionController::Base.relative_url_root
|
188
|
+
ActionController::Base.relative_url_root = '/subdir'
|
189
189
|
|
190
190
|
add_host!
|
191
191
|
assert_equal('https://www.basecamphq.com/subdir/c/a/i',
|
192
192
|
W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
|
193
193
|
)
|
194
194
|
ensure
|
195
|
-
ActionController::
|
195
|
+
ActionController::Base.relative_url_root = orig_relative_url_root
|
196
196
|
end
|
197
197
|
|
198
198
|
def test_named_routes
|
@@ -217,8 +217,8 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def test_relative_url_root_is_respected_for_named_routes
|
220
|
-
orig_relative_url_root = ActionController::
|
221
|
-
ActionController::
|
220
|
+
orig_relative_url_root = ActionController::Base.relative_url_root
|
221
|
+
ActionController::Base.relative_url_root = '/subdir'
|
222
222
|
|
223
223
|
ActionController::Routing::Routes.draw do |map|
|
224
224
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
@@ -231,7 +231,7 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
231
231
|
controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again')
|
232
232
|
ensure
|
233
233
|
ActionController::Routing::Routes.load!
|
234
|
-
ActionController::
|
234
|
+
ActionController::Base.relative_url_root = orig_relative_url_root
|
235
235
|
end
|
236
236
|
|
237
237
|
def test_only_path
|
@@ -239,14 +239,14 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
239
239
|
map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index'
|
240
240
|
map.connect ':controller/:action/:id'
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
# We need to create a new class in order to install the new named route.
|
244
244
|
kls = Class.new { include ActionController::UrlWriter }
|
245
245
|
controller = kls.new
|
246
246
|
assert controller.respond_to?(:home_url)
|
247
247
|
assert_equal '/brave/new/world',
|
248
248
|
controller.send(:url_for, :controller => 'brave', :action => 'new', :id => 'world', :only_path => true)
|
249
|
-
|
249
|
+
|
250
250
|
assert_equal("/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'unused', :only_path => true))
|
251
251
|
assert_equal("/home/sweet/home/alabama", controller.send(:home_path, 'alabama'))
|
252
252
|
ensure
|
@@ -306,5 +306,4 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
306
306
|
def extract_params(url)
|
307
307
|
url.split('?', 2).last.split('&')
|
308
308
|
end
|
309
|
-
|
310
309
|
end
|