actionpack 2.2.3 → 2.3.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 +433 -375
- data/MIT-LICENSE +1 -1
- data/README +21 -75
- data/Rakefile +1 -1
- data/lib/action_controller.rb +80 -43
- data/lib/action_controller/assertions/model_assertions.rb +1 -0
- data/lib/action_controller/assertions/response_assertions.rb +43 -16
- data/lib/action_controller/assertions/routing_assertions.rb +1 -1
- data/lib/action_controller/assertions/selector_assertions.rb +17 -12
- data/lib/action_controller/assertions/tag_assertions.rb +1 -4
- data/lib/action_controller/base.rb +153 -82
- data/lib/action_controller/benchmarking.rb +9 -9
- data/lib/action_controller/caching.rb +9 -11
- data/lib/action_controller/caching/actions.rb +11 -18
- data/lib/action_controller/caching/fragments.rb +28 -20
- data/lib/action_controller/caching/pages.rb +13 -15
- data/lib/action_controller/caching/sweeping.rb +2 -2
- data/lib/action_controller/cgi_ext.rb +0 -1
- data/lib/action_controller/cgi_ext/cookie.rb +2 -0
- data/lib/action_controller/cgi_process.rb +54 -162
- data/lib/action_controller/cookies.rb +13 -25
- data/lib/action_controller/dispatcher.rb +43 -122
- data/lib/action_controller/failsafe.rb +52 -0
- data/lib/action_controller/flash.rb +38 -47
- data/lib/action_controller/helpers.rb +13 -9
- data/lib/action_controller/http_authentication.rb +203 -23
- data/lib/action_controller/integration.rb +126 -70
- data/lib/action_controller/layout.rb +36 -39
- data/lib/action_controller/middleware_stack.rb +119 -0
- data/lib/action_controller/middlewares.rb +13 -0
- data/lib/action_controller/mime_responds.rb +19 -4
- data/lib/action_controller/mime_type.rb +8 -0
- data/lib/action_controller/params_parser.rb +71 -0
- data/lib/action_controller/performance_test.rb +0 -1
- data/lib/action_controller/polymorphic_routes.rb +36 -30
- data/lib/action_controller/reloader.rb +14 -0
- data/lib/action_controller/request.rb +107 -499
- data/lib/action_controller/request_forgery_protection.rb +7 -39
- data/lib/action_controller/rescue.rb +55 -35
- data/lib/action_controller/resources.rb +34 -31
- data/lib/action_controller/response.rb +99 -57
- data/lib/action_controller/rewindable_input.rb +28 -0
- data/lib/action_controller/routing.rb +7 -7
- data/lib/action_controller/routing/builder.rb +4 -1
- data/lib/action_controller/routing/optimisations.rb +1 -1
- data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
- data/lib/action_controller/routing/route.rb +15 -5
- data/lib/action_controller/routing/route_set.rb +82 -35
- data/lib/action_controller/routing/segments.rb +35 -0
- data/lib/action_controller/session/abstract_store.rb +181 -0
- data/lib/action_controller/session/cookie_store.rb +197 -175
- data/lib/action_controller/session/mem_cache_store.rb +36 -83
- data/lib/action_controller/session_management.rb +26 -134
- data/lib/action_controller/streaming.rb +24 -7
- 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 +87 -30
- data/lib/action_controller/test_process.rb +145 -104
- data/lib/action_controller/uploaded_file.rb +44 -0
- data/lib/action_controller/url_rewriter.rb +3 -6
- data/lib/action_controller/vendor/html-scanner.rb +16 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
- data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
- data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
- data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
- data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
- data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
- data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
- data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
- data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
- data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
- data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
- data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
- data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
- data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
- data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
- data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
- data/lib/action_controller/verification.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +22 -17
- data/lib/action_view/base.rb +53 -79
- data/lib/action_view/erb/util.rb +38 -0
- data/lib/action_view/helpers.rb +24 -5
- data/lib/action_view/helpers/active_record_helper.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
- data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/lib/action_view/helpers/benchmark_helper.rb +26 -5
- data/lib/action_view/helpers/date_helper.rb +82 -7
- data/lib/action_view/helpers/form_helper.rb +295 -64
- data/lib/action_view/helpers/form_options_helper.rb +160 -18
- data/lib/action_view/helpers/form_tag_helper.rb +2 -2
- data/lib/action_view/helpers/number_helper.rb +31 -18
- data/lib/action_view/helpers/prototype_helper.rb +2 -12
- data/lib/action_view/helpers/sanitize_helper.rb +0 -10
- data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
- data/lib/action_view/helpers/tag_helper.rb +3 -4
- data/lib/action_view/helpers/text_helper.rb +99 -122
- data/lib/action_view/helpers/translation_helper.rb +19 -1
- data/lib/action_view/helpers/url_helper.rb +25 -2
- data/lib/action_view/inline_template.rb +1 -1
- data/lib/action_view/locale/en.yml +19 -1
- data/lib/action_view/partials.rb +46 -9
- data/lib/action_view/paths.rb +28 -84
- data/lib/action_view/reloadable_template.rb +117 -0
- data/lib/action_view/renderable.rb +28 -35
- data/lib/action_view/renderable_partial.rb +3 -4
- data/lib/action_view/template.rb +172 -31
- data/lib/action_view/template_error.rb +8 -9
- data/lib/action_view/template_handler.rb +1 -1
- data/lib/action_view/template_handlers.rb +9 -6
- data/lib/action_view/template_handlers/erb.rb +2 -39
- data/lib/action_view/template_handlers/rjs.rb +1 -0
- data/lib/action_view/test_case.rb +27 -1
- data/test/abstract_unit.rb +23 -17
- data/test/active_record_unit.rb +5 -4
- data/test/activerecord/active_record_store_test.rb +139 -106
- data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
- data/test/controller/action_pack_assertions_test.rb +25 -23
- data/test/controller/addresses_render_test.rb +3 -6
- data/test/controller/assert_select_test.rb +83 -70
- data/test/controller/base_test.rb +11 -13
- data/test/controller/benchmark_test.rb +3 -3
- data/test/controller/caching_test.rb +34 -24
- data/test/controller/capture_test.rb +3 -6
- data/test/controller/content_type_test.rb +3 -6
- data/test/controller/cookie_test.rb +31 -66
- data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
- data/test/controller/dispatcher_test.rb +23 -28
- data/test/controller/fake_models.rb +8 -0
- data/test/controller/filters_test.rb +6 -2
- data/test/controller/flash_test.rb +2 -6
- data/test/controller/helper_test.rb +15 -1
- data/test/controller/html-scanner/document_test.rb +1 -1
- data/test/controller/html-scanner/sanitizer_test.rb +1 -1
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +56 -52
- data/test/controller/layout_test.rb +46 -44
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +7 -11
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/polymorphic_routes_test.rb +235 -151
- data/test/controller/rack_test.rb +52 -81
- data/test/controller/redirect_test.rb +6 -14
- data/test/controller/render_test.rb +273 -60
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +17 -98
- data/test/controller/request_test.rb +45 -530
- data/test/controller/rescue_test.rb +45 -22
- data/test/controller/resources_test.rb +112 -37
- data/test/controller/routing_test.rb +1442 -1384
- data/test/controller/selector_test.rb +3 -3
- data/test/controller/send_file_test.rb +30 -3
- data/test/controller/session/cookie_store_test.rb +169 -240
- data/test/controller/session/mem_cache_store_test.rb +94 -148
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +32 -13
- data/test/controller/url_rewriter_test.rb +54 -4
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -15
- data/test/controller/webservice_test.rb +178 -147
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
- data/test/fixtures/layouts/default_html.html.erb +1 -0
- data/test/fixtures/layouts/xhr.html.erb +2 -0
- data/test/fixtures/multipart/empty +10 -0
- data/test/fixtures/multipart/hello.txt +1 -0
- data/test/fixtures/multipart/none +9 -0
- data/test/fixtures/public/500.da.html +1 -0
- data/test/fixtures/quiz/questions/_question.html.erb +1 -0
- data/test/fixtures/replies.yml +1 -1
- data/test/fixtures/test/_one.html.erb +1 -0
- data/test/fixtures/test/_two.html.erb +1 -0
- data/test/fixtures/test/dont_pick_me +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hello_world.da.html.erb +1 -0
- data/test/fixtures/test/hello_world.erb~ +1 -0
- data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
- data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
- data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
- data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
- data/test/fixtures/test/utf8.html.erb +2 -0
- data/test/template/active_record_helper_i18n_test.rb +31 -33
- data/test/template/active_record_helper_test.rb +34 -0
- data/test/template/asset_tag_helper_test.rb +52 -14
- data/test/template/atom_feed_helper_test.rb +3 -5
- data/test/template/benchmark_helper_test.rb +50 -24
- data/test/template/compiled_templates_test.rb +177 -33
- data/test/template/date_helper_i18n_test.rb +88 -81
- data/test/template/date_helper_test.rb +427 -43
- data/test/template/form_helper_test.rb +243 -44
- data/test/template/form_options_helper_test.rb +631 -565
- data/test/template/form_tag_helper_test.rb +9 -2
- data/test/template/javascript_helper_test.rb +0 -5
- data/test/template/number_helper_i18n_test.rb +60 -48
- data/test/template/number_helper_test.rb +1 -0
- data/test/template/render_test.rb +117 -35
- data/test/template/test_test.rb +4 -6
- data/test/template/text_helper_test.rb +129 -50
- data/test/template/translation_helper_test.rb +23 -19
- data/test/template/url_helper_test.rb +35 -2
- data/test/view/test_case_test.rb +8 -0
- metadata +197 -23
- data/lib/action_controller/assertions.rb +0 -69
- data/lib/action_controller/caching/sql_cache.rb +0 -18
- data/lib/action_controller/cgi_ext/session.rb +0 -53
- data/lib/action_controller/components.rb +0 -169
- data/lib/action_controller/rack_process.rb +0 -297
- data/lib/action_controller/request_profiler.rb +0 -169
- data/lib/action_controller/session/active_record_store.rb +0 -340
- data/lib/action_controller/session/drb_server.rb +0 -32
- data/lib/action_controller/session/drb_store.rb +0 -35
- data/test/controller/cgi_test.rb +0 -269
- data/test/controller/components_test.rb +0 -156
- data/test/controller/http_authentication_test.rb +0 -54
- data/test/controller/integration_upload_test.rb +0 -43
- data/test/controller/session_fixation_test.rb +0 -89
- data/test/controller/session_management_test.rb +0 -178
- data/test/fixtures/test/hello_world.js +0 -1
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<html><%= @content_for_layout %></html>
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello
|
@@ -0,0 +1 @@
|
|
1
|
+
500 localized error fixture
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= question.name %>
|
data/test/fixtures/replies.yml
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<%= render :partial => "two" %> world
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello
|
@@ -0,0 +1 @@
|
|
1
|
+
non-template file
|
@@ -0,0 +1 @@
|
|
1
|
+
Hey verden
|
@@ -0,0 +1 @@
|
|
1
|
+
Don't pick me!
|
@@ -0,0 +1 @@
|
|
1
|
+
Ola mundo
|
@@ -0,0 +1 @@
|
|
1
|
+
Don't render me!
|
@@ -0,0 +1 @@
|
|
1
|
+
Don't render me!
|
@@ -0,0 +1 @@
|
|
1
|
+
Don't render me!
|
@@ -0,0 +1 @@
|
|
1
|
+
page.call "document.write", render(:partial => "one.html.erb")
|
@@ -0,0 +1 @@
|
|
1
|
+
page.call "document.write", render(:partial => "one")
|
@@ -0,0 +1 @@
|
|
1
|
+
Hey HTML!
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello HTML!
|
@@ -0,0 +1 @@
|
|
1
|
+
alert('hello');
|
@@ -4,43 +4,41 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase
|
|
4
4
|
include ActionView::Helpers::ActiveRecordHelper
|
5
5
|
|
6
6
|
attr_reader :request
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
stubs(:content_tag).returns 'content_tag'
|
7
|
+
def setup
|
8
|
+
@object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
|
9
|
+
@object_name = 'book'
|
10
|
+
stubs(:content_tag).returns 'content_tag'
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
|
13
|
+
I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
|
17
|
+
I18n.expects(:translate).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').never
|
18
|
+
error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def test_error_messages_for_given_no_header_option_it_translates_header_message
|
22
|
+
I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => '').returns 'header message'
|
23
|
+
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
24
|
+
error_messages_for(:object => @object, :locale => 'en')
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def test_error_messages_for_given_a_message_option_it_does_not_translate_message
|
28
|
+
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).never
|
29
|
+
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
30
|
+
error_messages_for(:object => @object, :message => 'message', :locale => 'en')
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
33
|
+
def test_error_messages_for_given_no_message_option_it_translates_message
|
34
|
+
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
|
35
|
+
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
|
36
|
+
error_messages_for(:object => @object, :locale => 'en')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_error_messages_for_given_object_name_it_translates_object_name
|
40
|
+
I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name).returns "1 error prohibited this #{@object_name} from being saved"
|
41
|
+
I18n.expects(:t).with(@object_name, :default => @object_name, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name
|
42
|
+
error_messages_for(:object => @object, :locale => 'en', :object_name => @object_name)
|
45
43
|
end
|
46
44
|
end
|
@@ -19,6 +19,30 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
19
19
|
Column = Struct.new("Column", :type, :name, :human_name)
|
20
20
|
end
|
21
21
|
|
22
|
+
class DirtyPost
|
23
|
+
class Errors
|
24
|
+
def empty?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def count
|
29
|
+
1
|
30
|
+
end
|
31
|
+
|
32
|
+
def full_messages
|
33
|
+
["Author name can't be <em>empty</em>"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def on(field)
|
37
|
+
"can't be <em>empty</em>"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def errors
|
42
|
+
Errors.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
22
46
|
def setup_post
|
23
47
|
@post = Post.new
|
24
48
|
def @post.errors
|
@@ -195,10 +219,20 @@ class ActiveRecordHelperTest < ActionView::TestCase
|
|
195
219
|
assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
|
196
220
|
end
|
197
221
|
|
222
|
+
def test_error_messages_for_escapes_html
|
223
|
+
@dirty_post = DirtyPost.new
|
224
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this dirty post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be <em>empty</em></li></ul></div>), error_messages_for("dirty_post")
|
225
|
+
end
|
226
|
+
|
198
227
|
def test_error_messages_for_handles_nil
|
199
228
|
assert_equal "", error_messages_for("notthere")
|
200
229
|
end
|
201
230
|
|
231
|
+
def test_error_message_on_escapes_html
|
232
|
+
@dirty_post = DirtyPost.new
|
233
|
+
assert_dom_equal "<div class=\"formError\">can't be <em>empty</em></div>", error_message_on(:dirty_post, :author_name)
|
234
|
+
end
|
235
|
+
|
202
236
|
def test_error_message_on_handles_nil
|
203
237
|
assert_equal "", error_message_on("notthere", "notthere")
|
204
238
|
end
|
@@ -228,20 +228,18 @@ class AssetTagHelperTest < ActionView::TestCase
|
|
228
228
|
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
229
229
|
end
|
230
230
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
ENV.delete("RAILS_ASSET_ID")
|
244
|
-
end
|
231
|
+
def test_image_tag_windows_behaviour
|
232
|
+
old_asset_id, ENV["RAILS_ASSET_ID"] = ENV["RAILS_ASSET_ID"], "1"
|
233
|
+
# This simulates the behaviour of File#exist? on windows when testing a file ending in "."
|
234
|
+
# If the file "rails.png" exists, windows will return true when asked if "rails.png." exists (notice trailing ".")
|
235
|
+
# OS X, linux etc will return false in this case.
|
236
|
+
File.stubs(:exist?).with('template/../fixtures/public/images/rails.png.').returns(true)
|
237
|
+
assert_equal '<img alt="Rails" src="/images/rails.png?1" />', image_tag('rails.png')
|
238
|
+
ensure
|
239
|
+
if old_asset_id
|
240
|
+
ENV["RAILS_ASSET_ID"] = old_asset_id
|
241
|
+
else
|
242
|
+
ENV.delete("RAILS_ASSET_ID")
|
245
243
|
end
|
246
244
|
end
|
247
245
|
|
@@ -377,6 +375,46 @@ class AssetTagHelperTest < ActionView::TestCase
|
|
377
375
|
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
|
378
376
|
end
|
379
377
|
|
378
|
+
def test_caching_javascript_include_tag_when_caching_on_with_2_argument_object_asset_host
|
379
|
+
ENV['RAILS_ASSET_ID'] = ''
|
380
|
+
ActionController::Base.asset_host = Class.new do
|
381
|
+
def call(source, request)
|
382
|
+
if request.ssl?
|
383
|
+
"#{request.protocol}#{request.host_with_port}"
|
384
|
+
else
|
385
|
+
"#{request.protocol}assets#{source.length}.example.com"
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end.new
|
389
|
+
|
390
|
+
ActionController::Base.perform_caching = true
|
391
|
+
|
392
|
+
assert_equal '/javascripts/vanilla.js'.length, 23
|
393
|
+
assert_dom_equal(
|
394
|
+
%(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>),
|
395
|
+
javascript_include_tag(:all, :cache => 'vanilla')
|
396
|
+
)
|
397
|
+
|
398
|
+
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
|
399
|
+
|
400
|
+
class << @controller.request
|
401
|
+
def protocol() 'https://' end
|
402
|
+
def ssl?() true end
|
403
|
+
end
|
404
|
+
|
405
|
+
assert_equal '/javascripts/secure.js'.length, 22
|
406
|
+
assert_dom_equal(
|
407
|
+
%(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>),
|
408
|
+
javascript_include_tag(:all, :cache => 'secure')
|
409
|
+
)
|
410
|
+
|
411
|
+
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
|
412
|
+
|
413
|
+
ensure
|
414
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
|
415
|
+
FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
|
416
|
+
end
|
417
|
+
|
380
418
|
def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
|
381
419
|
ENV["RAILS_ASSET_ID"] = ""
|
382
420
|
ActionController::Base.asset_host = 'http://a%d.example.com'
|
@@ -166,12 +166,10 @@ class ScrollsController < ActionController::Base
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
class AtomFeedTest <
|
170
|
-
|
171
|
-
@request = ActionController::TestRequest.new
|
172
|
-
@response = ActionController::TestResponse.new
|
173
|
-
@controller = ScrollsController.new
|
169
|
+
class AtomFeedTest < ActionController::TestCase
|
170
|
+
tests ScrollsController
|
174
171
|
|
172
|
+
def setup
|
175
173
|
@request.host = "www.nextangle.com"
|
176
174
|
end
|
177
175
|
|
@@ -4,32 +4,25 @@ require 'action_view/helpers/benchmark_helper'
|
|
4
4
|
class BenchmarkHelperTest < ActionView::TestCase
|
5
5
|
tests ActionView::Helpers::BenchmarkHelper
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@logged = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(method, *args)
|
15
|
-
@logged << [method, args]
|
16
|
-
end
|
7
|
+
def teardown
|
8
|
+
controller.logger.send(:clear_buffer)
|
17
9
|
end
|
18
10
|
|
19
11
|
def controller
|
20
|
-
|
12
|
+
logger = ActiveSupport::BufferedLogger.new(StringIO.new)
|
13
|
+
logger.auto_flushing = false
|
14
|
+
@controller ||= Struct.new(:logger).new(logger)
|
21
15
|
end
|
22
16
|
|
23
17
|
def test_without_block
|
24
18
|
assert_raise(LocalJumpError) { benchmark }
|
25
|
-
assert
|
19
|
+
assert buffer.empty?
|
26
20
|
end
|
27
21
|
|
28
22
|
def test_defaults
|
29
23
|
i_was_run = false
|
30
24
|
benchmark { i_was_run = true }
|
31
25
|
assert i_was_run
|
32
|
-
assert 1, controller.logger.logged.size
|
33
26
|
assert_last_logged
|
34
27
|
end
|
35
28
|
|
@@ -37,24 +30,57 @@ class BenchmarkHelperTest < ActionView::TestCase
|
|
37
30
|
i_was_run = false
|
38
31
|
benchmark('test_run') { i_was_run = true }
|
39
32
|
assert i_was_run
|
40
|
-
assert 1, controller.logger.logged.size
|
41
33
|
assert_last_logged 'test_run'
|
42
34
|
end
|
43
35
|
|
44
|
-
def
|
36
|
+
def test_with_message_and_deprecated_level
|
45
37
|
i_was_run = false
|
46
|
-
|
38
|
+
|
39
|
+
assert_deprecated do
|
40
|
+
benchmark('debug_run', :debug) { i_was_run = true }
|
41
|
+
end
|
42
|
+
|
47
43
|
assert i_was_run
|
48
|
-
|
49
|
-
|
44
|
+
assert_last_logged 'debug_run'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_within_level
|
48
|
+
controller.logger.level = ActiveSupport::BufferedLogger::DEBUG
|
49
|
+
benchmark('included_debug_run', :level => :debug) { }
|
50
|
+
assert_last_logged 'included_debug_run'
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_outside_level
|
54
|
+
controller.logger.level = ActiveSupport::BufferedLogger::ERROR
|
55
|
+
benchmark('skipped_debug_run', :level => :debug) { }
|
56
|
+
assert_no_match(/skipped_debug_run/, buffer.last)
|
57
|
+
ensure
|
58
|
+
controller.logger.level = ActiveSupport::BufferedLogger::DEBUG
|
50
59
|
end
|
51
60
|
|
61
|
+
def test_without_silencing
|
62
|
+
benchmark('debug_run', :silence => false) do
|
63
|
+
controller.logger.info "not silenced!"
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_equal 2, buffer.size
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_with_silencing
|
70
|
+
benchmark('debug_run', :silence => true) do
|
71
|
+
controller.logger.info "silenced!"
|
72
|
+
end
|
73
|
+
|
74
|
+
assert_equal 1, buffer.size
|
75
|
+
end
|
76
|
+
|
77
|
+
|
52
78
|
private
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
79
|
+
def buffer
|
80
|
+
controller.logger.send(:buffer)
|
81
|
+
end
|
82
|
+
|
83
|
+
def assert_last_logged(message = 'Benchmarking')
|
84
|
+
assert_match(/^#{message} \(.*\)$/, buffer.last)
|
59
85
|
end
|
60
86
|
end
|
@@ -1,59 +1,203 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
require 'controller/fake_models'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
class CompiledTemplatesTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@compiled_templates = ActionView::Base::CompiledTemplates
|
8
|
+
@compiled_templates.instance_methods.each do |m|
|
9
|
+
@compiled_templates.send(:remove_method, m) if m =~ /^_run_/
|
11
10
|
end
|
11
|
+
end
|
12
12
|
|
13
|
-
|
13
|
+
def test_template_gets_compiled
|
14
|
+
with_caching(true) do
|
14
15
|
assert_equal 0, @compiled_templates.instance_methods.size
|
15
|
-
|
16
|
-
assert_equal "Hello world!", render("test/hello_world.erb")
|
17
|
-
end
|
16
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
18
17
|
assert_equal 1, @compiled_templates.instance_methods.size
|
19
18
|
end
|
19
|
+
end
|
20
20
|
|
21
|
-
|
21
|
+
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
|
22
|
+
with_caching(true) do
|
22
23
|
assert_equal 0, @compiled_templates.instance_methods.size
|
23
|
-
|
24
|
-
|
25
|
-
assert_equal "Hello world!", render("test/hello_world.erb", {:foo => "bar"})
|
26
|
-
end
|
24
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
25
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb", :locals => {:foo => "bar"})
|
27
26
|
assert_equal 2, @compiled_templates.instance_methods.size
|
28
27
|
end
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_local_assigns
|
31
|
+
with_caching(true) do
|
31
32
|
assert_equal 0, @compiled_templates.instance_methods.size
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
34
|
+
ActionView::Template.any_instance.expects(:compile!).never
|
35
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_template_changes_are_not_reflected_with_cached_template_loading
|
40
|
+
with_caching(true) do
|
41
|
+
with_reloading(false) do
|
42
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
43
|
+
modify_template "test/hello_world.erb", "Goodbye world!" do
|
44
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
45
|
+
end
|
46
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
36
47
|
end
|
37
48
|
end
|
49
|
+
end
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
51
|
+
def test_template_changes_are_reflected_without_cached_template_loading
|
52
|
+
with_caching(true) do
|
53
|
+
with_reloading(true) do
|
54
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
55
|
+
modify_template "test/hello_world.erb", "Goodbye world!" do
|
56
|
+
assert_equal "Goodbye world!", render(:file => "test/hello_world.erb")
|
57
|
+
end
|
58
|
+
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
42
62
|
|
43
|
-
|
44
|
-
|
63
|
+
def test_template_becomes_missing_if_deleted_without_cached_template_loading
|
64
|
+
with_reloading(true) do
|
65
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world.erb')
|
66
|
+
delete_template 'test/hello_world.erb' do
|
67
|
+
assert_raise(ActionView::MissingTemplate) { render(:file => 'test/hello_world.erb') }
|
45
68
|
end
|
69
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world.erb')
|
70
|
+
end
|
71
|
+
end
|
46
72
|
|
47
|
-
|
48
|
-
|
49
|
-
|
73
|
+
def test_swapping_template_handler_is_working_without_cached_template_loading
|
74
|
+
with_reloading(true) do
|
75
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
76
|
+
delete_template 'test/hello_world.erb' do
|
77
|
+
rename_template 'test/hello_world_from_rxml.builder', 'test/hello_world.builder' do
|
78
|
+
assert_equal "<html>\n <p>Hello</p>\n</html>\n", render(:file => 'test/hello_world')
|
79
|
+
end
|
50
80
|
end
|
51
|
-
assert_equal
|
81
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
52
82
|
end
|
83
|
+
end
|
53
84
|
|
54
|
-
|
55
|
-
|
56
|
-
|
85
|
+
def test_adding_localized_template_will_take_precedence_without_cached_template_loading
|
86
|
+
with_reloading(true) do
|
87
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
88
|
+
rename_template 'test/hello_world.da.html.erb', 'test/hello_world.en.html.erb' do
|
89
|
+
assert_equal 'Hey verden', render(:file => 'test/hello_world')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_deleting_localized_template_will_fall_back_to_non_localized_template_without_cached_template_loading
|
95
|
+
with_reloading(true) do
|
96
|
+
rename_template 'test/hello_world.da.html.erb', 'test/hello_world.en.html.erb' do
|
97
|
+
assert_equal 'Hey verden', render(:file => 'test/hello_world')
|
98
|
+
delete_template 'test/hello_world.en.html.erb' do
|
99
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
100
|
+
end
|
101
|
+
assert_equal 'Hey verden', render(:file => 'test/hello_world')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_parallel_reloadable_view_paths_are_working
|
107
|
+
with_reloading(true) do
|
108
|
+
view_paths_copy = new_reloadable_view_paths
|
109
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
110
|
+
with_view_paths(view_paths_copy, new_reloadable_view_paths) do
|
111
|
+
assert_equal 'Hello world!', render(:file => 'test/hello_world')
|
112
|
+
end
|
113
|
+
modify_template 'test/hello_world.erb', 'Goodbye world!' do
|
114
|
+
assert_equal 'Goodbye world!', render(:file => 'test/hello_world')
|
115
|
+
modify_template 'test/hello_world.erb', 'So long, world!' do
|
116
|
+
with_view_paths(view_paths_copy, new_reloadable_view_paths) do
|
117
|
+
assert_equal 'So long, world!', render(:file => 'test/hello_world')
|
118
|
+
end
|
119
|
+
assert_equal 'So long, world!', render(:file => 'test/hello_world')
|
120
|
+
end
|
57
121
|
end
|
122
|
+
end
|
58
123
|
end
|
124
|
+
|
125
|
+
private
|
126
|
+
def render(*args)
|
127
|
+
view_paths = @explicit_view_paths || ActionController::Base.view_paths
|
128
|
+
ActionView::Base.new(view_paths, {}).render(*args)
|
129
|
+
end
|
130
|
+
|
131
|
+
def with_view_paths(*args)
|
132
|
+
args.each do |view_paths|
|
133
|
+
begin
|
134
|
+
@explicit_view_paths = view_paths
|
135
|
+
yield
|
136
|
+
ensure
|
137
|
+
@explicit_view_paths = nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def reset_mtime_of(template_name, view_paths_to_use)
|
143
|
+
view_paths_to_use.find_template(template_name).previously_last_modified = 10.seconds.ago unless ActionView::Base.cache_template_loading?
|
144
|
+
end
|
145
|
+
|
146
|
+
def modify_template(template, content, view_paths_to_use = ActionController::Base.view_paths)
|
147
|
+
filename = filename_for(template)
|
148
|
+
old_content = File.read(filename)
|
149
|
+
begin
|
150
|
+
File.open(filename, "wb+") { |f| f.write(content) }
|
151
|
+
reset_mtime_of(template, view_paths_to_use)
|
152
|
+
yield
|
153
|
+
ensure
|
154
|
+
File.open(filename, "wb+") { |f| f.write(old_content) }
|
155
|
+
reset_mtime_of(template, view_paths_to_use)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def filename_for(template)
|
160
|
+
File.join(FIXTURE_LOAD_PATH, template)
|
161
|
+
end
|
162
|
+
|
163
|
+
def rename_template(old_name, new_name)
|
164
|
+
File.rename(filename_for(old_name), filename_for(new_name))
|
165
|
+
yield
|
166
|
+
ensure
|
167
|
+
File.rename(filename_for(new_name), filename_for(old_name))
|
168
|
+
end
|
169
|
+
|
170
|
+
def delete_template(template, &block)
|
171
|
+
rename_template(template, File.join(File.dirname(template), "__#{File.basename(template)}"), &block)
|
172
|
+
end
|
173
|
+
|
174
|
+
def with_caching(perform_caching)
|
175
|
+
old_perform_caching = ActionController::Base.perform_caching
|
176
|
+
begin
|
177
|
+
ActionController::Base.perform_caching = perform_caching
|
178
|
+
yield
|
179
|
+
ensure
|
180
|
+
ActionController::Base.perform_caching = old_perform_caching
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def with_reloading(reload_templates, view_paths_owner = ActionController::Base)
|
185
|
+
old_view_paths, old_cache_templates = view_paths_owner.view_paths, ActionView::Base.cache_template_loading
|
186
|
+
begin
|
187
|
+
ActionView::Base.cache_template_loading = !reload_templates
|
188
|
+
view_paths_owner.view_paths = view_paths_for(reload_templates)
|
189
|
+
yield
|
190
|
+
ensure
|
191
|
+
view_paths_owner.view_paths, ActionView::Base.cache_template_loading = old_view_paths, old_cache_templates
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def new_reloadable_view_paths
|
196
|
+
ActionView::PathSet.new(CACHED_VIEW_PATHS.map(&:to_s))
|
197
|
+
end
|
198
|
+
|
199
|
+
def view_paths_for(reload_templates)
|
200
|
+
# reloadable paths are cheap to create
|
201
|
+
reload_templates ? new_reloadable_view_paths : CACHED_VIEW_PATHS
|
202
|
+
end
|
59
203
|
end
|