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