From ec94c2550dae463e646a18316bfcdaded9d140c9 Mon Sep 17 00:00:00 2001 From: Sava Chankov Date: Sat, 1 Aug 2009 19:38:05 -0700 Subject: Ruby 1.9: fix Content-Length for multibyte send_data streaming [#2661 state:resolved] Signed-off-by: Jeremy Kemper --- actionpack/test/controller/send_file_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index ae32ee5649..154daad1b9 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require 'abstract_unit' module TestFileUtils @@ -22,6 +23,10 @@ class SendFileController < ActionController::Base def data send_data(file_data, options) end + + def multibyte_text_data + send_data("Кирилица\n祝您好運", options) + end end class SendFileTest < ActionController::TestCase @@ -163,4 +168,11 @@ class SendFileTest < ActionController::TestCase assert_equal 200, @response.status end end + + def test_send_data_content_length_header + @controller.headers = {} + @controller.options = { :type => :text, :filename => 'file_with_utf8_text' } + process('multibyte_text_data') + assert_equal '29', @controller.headers['Content-Length'] + end end -- cgit v1.2.3 From f2a35723c8876697d5a7ebfdf329cee54d8a39ac Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 1 Aug 2009 20:07:28 -0700 Subject: Ruby 1.9: fix encoding for test_file_stream --- actionpack/test/controller/send_file_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 154daad1b9..f0c723eaa2 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -4,7 +4,7 @@ require 'abstract_unit' module TestFileUtils def file_name() File.basename(__FILE__) end def file_path() File.expand_path(__FILE__) end - def file_data() File.open(file_path, 'rb') { |f| f.read } end + def file_data() @data ||= File.open(file_path, 'rb') { |f| f.read } end end class SendFileController < ActionController::Base @@ -60,6 +60,7 @@ class SendFileTest < ActionController::TestCase require 'stringio' output = StringIO.new output.binmode + output.string.force_encoding(file_data.encoding) if output.string.respond_to?(:force_encoding) assert_nothing_raised { response.body_parts.each { |part| output << part.to_s } } assert_equal file_data, output.string end -- cgit v1.2.3 From 503ce1d01ce6c8eee9818f4e76a9f880bb1a291d Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 30 Jul 2009 21:00:39 -0700 Subject: Update cache_control to be a Hash of options that is used to build the header. * Significantly simplifies setting and modifying cache control in other areas --- actionpack/test/controller/render_test.rb | 2 +- actionpack/test/controller/send_file_test.rb | 2 +- actionpack/test/dispatch/response_test.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index acb0c895e0..d0fa67c945 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1331,7 +1331,7 @@ class EtagRenderTest < ActionController::TestCase def test_render_200_should_set_etag get :render_hello_world_from_variable assert_equal etag_for("hello david"), @response.headers['ETag'] - assert_equal "private, max-age=0, must-revalidate", @response.headers['Cache-Control'] + assert_equal "max-age=0, private, must-revalidate", @response.headers['Cache-Control'] end def test_render_against_etag_request_should_304_when_match diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index f0c723eaa2..0afebac68c 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -129,7 +129,7 @@ class SendFileTest < ActionController::TestCase # test overriding Cache-Control: no-cache header to fix IE open/save dialog @controller.headers = { 'Cache-Control' => 'no-cache' } @controller.send(:send_file_headers!, options) - h = @controller.headers + @controller.response.prepare! assert_equal 'private', h['Cache-Control'] end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 2ddc6cb2b5..2b1540c678 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -13,7 +13,7 @@ class ResponseTest < ActiveSupport::TestCase assert_equal 200, status assert_equal({ "Content-Type" => "text/html; charset=utf-8", - "Cache-Control" => "private, max-age=0, must-revalidate", + "Cache-Control" => "max-age=0, private, must-revalidate", "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', "Set-Cookie" => "", "Content-Length" => "13" @@ -32,7 +32,7 @@ class ResponseTest < ActiveSupport::TestCase assert_equal 200, status assert_equal({ "Content-Type" => "text/html; charset=utf-8", - "Cache-Control" => "private, max-age=0, must-revalidate", + "Cache-Control" => "max-age=0, private, must-revalidate", "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"', "Set-Cookie" => "", "Content-Length" => "8" -- cgit v1.2.3 From b53f00690173797a39ff46e55dd25c20581c3d00 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 30 Jul 2009 21:32:24 -0700 Subject: Remove legacy processing and content_length * convert_content_type! is handled by assign_default_content_type_and_charset! * set_content_length! should be handled by the endpoint server. Otherwise each middleware that modifies the body has to do the expensive work of recalculating content_length. * convert_language! appears to be legacy. There are no tests for this * convert_cookies! should be handled by the new HeaderHash in Rack * Use an integer for .status's internal representation to avoid needing to do String manipulation just to find out the status --- actionpack/test/dispatch/request/multipart_params_parsing_test.rb | 2 -- actionpack/test/dispatch/response_test.rb | 6 ++---- actionpack/test/new_base/base_test.rb | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 9e008a9ae8..301080842e 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -120,8 +120,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest fixture = FIXTURE_PATH + "/mona_lisa.jpg" params = { :uploaded_data => fixture_file_upload(fixture, "image/jpg") } post '/read', params - expected_length = 'File: '.length + File.size(fixture) - assert_equal expected_length, response.content_length end end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 2b1540c678..256ed06a45 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -15,8 +15,7 @@ class ResponseTest < ActiveSupport::TestCase "Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "max-age=0, private, must-revalidate", "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', - "Set-Cookie" => "", - "Content-Length" => "13" + "Set-Cookie" => "" }, headers) parts = [] @@ -34,8 +33,7 @@ class ResponseTest < ActiveSupport::TestCase "Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "max-age=0, private, must-revalidate", "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"', - "Set-Cookie" => "", - "Content-Length" => "8" + "Set-Cookie" => "" }, headers) end diff --git a/actionpack/test/new_base/base_test.rb b/actionpack/test/new_base/base_test.rb index d9d552f9e5..1b2e917ced 100644 --- a/actionpack/test/new_base/base_test.rb +++ b/actionpack/test/new_base/base_test.rb @@ -34,7 +34,6 @@ module Dispatching assert_body "success" assert_status 200 assert_content_type "text/html; charset=utf-8" - assert_header "Content-Length", "7" end # :api: plugin @@ -42,7 +41,6 @@ module Dispatching get "/dispatching/simple/modify_response_body" assert_body "success" - assert_header "Content-Length", "7" # setting the body manually sets the content length end # :api: plugin @@ -50,7 +48,6 @@ module Dispatching get "/dispatching/simple/modify_response_body_twice" assert_body "success!" - assert_header "Content-Length", "8" end test "controller path" do -- cgit v1.2.3 From 64268a0b06d32567c6e88b7293f332b79e10414b Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Wed, 5 Aug 2009 15:58:55 +0100 Subject: Make sure javascript_include_tag/stylesheet_link_tag does not append ".js" or ".css" onto external urls [#1664 state:resolved] Signed-off-by: Pratik Naik --- actionpack/test/template/asset_tag_helper_test.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 08963946ab..28f9d48671 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -83,7 +83,10 @@ class AssetTagHelperTest < ActionView::TestCase %(javascript_include_tag(:all)) => %(\n\n\n\n\n\n\n), %(javascript_include_tag(:all, :recursive => true)) => %(\n\n\n\n\n\n\n\n), %(javascript_include_tag(:defaults, "bank")) => %(\n\n\n\n\n), - %(javascript_include_tag("bank", :defaults)) => %(\n\n\n\n\n) + %(javascript_include_tag("bank", :defaults)) => %(\n\n\n\n\n), + + %(javascript_include_tag("http://example.com/all")) => %(), + %(javascript_include_tag("http://example.com/all.js")) => %(), } StylePathToTag = { @@ -111,7 +114,8 @@ class AssetTagHelperTest < ActionView::TestCase %(stylesheet_link_tag(:all, :media => "all")) => %(\n\n), %(stylesheet_link_tag("random.styles", "/elsewhere/file")) => %(\n), - %(stylesheet_link_tag("http://www.example.com/styles/style")) => %() + %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(), + %(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %(), } ImagePathToTag = { -- cgit v1.2.3 From af375a5eb3aba149590be1636480e1c3976c124f Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 6 Aug 2009 19:45:40 -0300 Subject: Replace _action_view with view_context to reflect that it is public and that it does not need to be an ActionView instance --- actionpack/test/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 6e71b85645..7f373ea7c5 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -78,7 +78,7 @@ module ActionController def assert_template(options = {}, message = nil) validate_request! - hax = @controller._action_view.instance_variable_get(:@_rendered) + hax = @controller.view_context.instance_variable_get(:@_rendered) case options when NilClass, String -- cgit v1.2.3 From 71638e6760bed0445e5fefc185924b07076fef47 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 6 Aug 2009 22:51:24 -0300 Subject: Move AbstractController to a top-level component --- actionpack/test/abstract_controller/test_helper.rb | 2 +- actionpack/test/abstract_unit.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_controller/test_helper.rb b/actionpack/test/abstract_controller/test_helper.rb index 915054f7fb..ba4302d914 100644 --- a/actionpack/test/abstract_controller/test_helper.rb +++ b/actionpack/test/abstract_controller/test_helper.rb @@ -6,7 +6,7 @@ require 'rubygems' require 'test/unit' require 'active_support' require 'active_support/test_case' -require 'action_controller/abstract' +require 'abstract_controller' require 'action_view' require 'action_view/base' require 'action_dispatch' diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 7f373ea7c5..b062a71442 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -13,7 +13,6 @@ require 'test/unit' require 'active_support' require 'active_support/test_case' -require 'action_controller/abstract' require 'action_controller' require 'fixture_template' require 'action_controller/testing/process' -- cgit v1.2.3 From 70a440aa277676078e3b8baafe1101d1287e114f Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 7 Aug 2009 00:52:13 -0300 Subject: Clean up render @object a bit more. --- .../test/controller/record_identifier_test.rb | 57 ---------------------- 1 file changed, 57 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/record_identifier_test.rb b/actionpack/test/controller/record_identifier_test.rb index 44e49ed3f8..6b6d154faa 100644 --- a/actionpack/test/controller/record_identifier_test.rb +++ b/actionpack/test/controller/record_identifier_test.rb @@ -54,24 +54,6 @@ class RecordIdentifierTest < Test::Unit::TestCase assert_equal "edit_#{@singular}_1", dom_id(@record, :edit) end - def test_partial_path - expected = "#{@plural}/#{@singular}" - assert_equal expected, partial_path(@record) - assert_equal expected, partial_path(Comment) - end - - def test_partial_path_with_namespaced_controller_path - expected = "admin/#{@plural}/#{@singular}" - assert_equal expected, partial_path(@record, "admin/posts") - assert_equal expected, partial_path(@klass, "admin/posts") - end - - def test_partial_path_with_not_namespaced_controller_path - expected = "#{@plural}/#{@singular}" - assert_equal expected, partial_path(@record, "posts") - assert_equal expected, partial_path(@klass, "posts") - end - def test_dom_class assert_equal @singular, dom_class(@record) end @@ -101,42 +83,3 @@ class RecordIdentifierTest < Test::Unit::TestCase RecordIdentifier.send(method, *args) end end - -class NestedRecordIdentifierTest < RecordIdentifierTest - def setup - @klass = Comment::Nested - @record = @klass.new - @singular = 'comment_nested' - @plural = 'comment_nesteds' - end - - def test_partial_path - expected = "comment/nesteds/nested" - assert_equal expected, partial_path(@record) - assert_equal expected, partial_path(Comment::Nested) - end - - def test_partial_path_with_namespaced_controller_path - expected = "admin/comment/nesteds/nested" - assert_equal expected, partial_path(@record, "admin/posts") - assert_equal expected, partial_path(@klass, "admin/posts") - end - - def test_partial_path_with_deeper_namespaced_controller_path - expected = "deeper/admin/comment/nesteds/nested" - assert_equal expected, partial_path(@record, "deeper/admin/posts") - assert_equal expected, partial_path(@klass, "deeper/admin/posts") - end - - def test_partial_path_with_even_deeper_namespaced_controller_path - expected = "even/more/deeper/admin/comment/nesteds/nested" - assert_equal expected, partial_path(@record, "even/more/deeper/admin/posts") - assert_equal expected, partial_path(@klass, "even/more/deeper/admin/posts") - end - - def test_partial_path_with_not_namespaced_controller_path - expected = "comment/nesteds/nested" - assert_equal expected, partial_path(@record, "posts") - assert_equal expected, partial_path(@klass, "posts") - end -end -- cgit v1.2.3 From 0612fd0f09977dece11a0325a0d7ee07c5cab35c Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 7 Aug 2009 03:18:45 -0300 Subject: Replace _render_template_with_layout with _render_template since the layout is optional --- actionpack/test/controller/logging_test.rb | 3 ++- actionpack/test/controller/render_test.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb index a7ed1b8665..98ffbc3813 100644 --- a/actionpack/test/controller/logging_test.rb +++ b/actionpack/test/controller/logging_test.rb @@ -17,9 +17,10 @@ class LoggingTest < ActionController::TestCase @level = Logger::DEBUG end - def method_missing(method, *args) + def method_missing(method, *args, &blk) @logged ||= [] @logged << args.first + @logged << blk.call if block_given? end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index d0fa67c945..947ffa9ea6 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -17,8 +17,9 @@ class MockLogger @logged = [] end - def method_missing(method, *args) + def method_missing(method, *args, &blk) @logged << args.first + @logged << blk.call if block_given? end end -- cgit v1.2.3