aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-05-02 14:57:40 -0500
committerJoshua Peek <josh@joshpeek.com>2009-05-02 14:57:40 -0500
commita8b75c480fc9774252f5976dcf1a614079822e56 (patch)
treeb2567b106a5a87472340bdeab54f4b1880fe06df
parent3900f4007ee6463b8936af23c04017a900673866 (diff)
downloadrails-a8b75c480fc9774252f5976dcf1a614079822e56.tar.gz
rails-a8b75c480fc9774252f5976dcf1a614079822e56.tar.bz2
rails-a8b75c480fc9774252f5976dcf1a614079822e56.zip
Functional test runner finalizes response just like the integration test runner. In both runners, the @response object will now behave the same.
Some functional tests will need to be updated if they are relying on preprocessed data on the response.
-rw-r--r--actionpack/lib/action_controller/testing/process.rb5
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb2
-rw-r--r--actionpack/lib/action_dispatch/testing/test_response.rb18
-rw-r--r--actionpack/test/controller/cookie_test.rb17
-rw-r--r--actionpack/test/controller/render_test.rb22
-rw-r--r--actionpack/test/controller/send_file_test.rb8
-rw-r--r--actionpack/test/controller/test_test.rb4
-rw-r--r--actionpack/test/template/body_parts_test.rb6
-rw-r--r--actionpack/test/template/output_buffer_test.rb42
9 files changed, 66 insertions, 58 deletions
diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb
index f62d18a1f9..b44ec2f94b 100644
--- a/actionpack/lib/action_controller/testing/process.rb
+++ b/actionpack/lib/action_controller/testing/process.rb
@@ -132,7 +132,10 @@ module ActionController #:nodoc:
Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest
- @controller.process(@request, @response)
+ response = Rack::MockResponse.new(*@controller.process(@request, ActionDispatch::Response.new).to_a)
+ @response.request, @response.template = @request, @controller.template
+ @response.status, @response.headers, @response.body = response.status, response.headers, response.body
+ @response
end
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 2618e284fe..133b4f7335 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -185,7 +185,7 @@ module ActionDispatch # :nodoc:
@writer = lambda { |x| callback.call(x) }
@body.call(self, self)
else
- @body.each(&callback)
+ @body.each { |part| callback.call(part.to_s) }
end
@writer = callback
diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb
index c5464f1559..c35982e075 100644
--- a/actionpack/lib/action_dispatch/testing/test_response.rb
+++ b/actionpack/lib/action_dispatch/testing/test_response.rb
@@ -93,6 +93,12 @@ module ActionDispatch
ActiveSupport::Deprecation.warn("response.has_template_object? has been deprecated. Use tempate.assigns[name].nil? instead", caller)
!template_objects[name].nil?
end
+
+ # Returns binary content (downloadable file), converted to a String
+ def binary_content
+ ActiveSupport::Deprecation.warn("response.binary_content has been deprecated. Use response.body instead", caller)
+ body
+ end
end
include DeprecatedHelpers
@@ -121,17 +127,5 @@ module ActionDispatch
def client_error?
(400..499).include?(response_code)
end
-
- # Returns binary content (downloadable file), converted to a String
- def binary_content
- raise "Response body is not a Proc: #{body_parts.inspect}" unless body_parts.kind_of?(Proc)
- require 'stringio'
-
- sio = StringIO.new
- body_parts.call(self, sio)
-
- sio.rewind
- sio.read
- end
end
end
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index c861982698..0f22714071 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -54,39 +54,38 @@ class CookieTest < ActionController::TestCase
def test_setting_cookie
get :authenticate
- assert_equal ["user_name=david; path=/"], @response.headers["Set-Cookie"]
+ assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_setting_with_escapable_characters
get :set_with_with_escapable_characters
- assert_equal ["that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"], @response.headers["Set-Cookie"]
+ assert_equal "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/", @response.headers["Set-Cookie"]
assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
end
def test_setting_cookie_for_fourteen_days
get :authenticate_for_fourteen_days
- assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
+ assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"]
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_setting_cookie_for_fourteen_days_with_symbols
get :authenticate_for_fourteen_days_with_symbols
- assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
+ assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"]
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_setting_cookie_with_http_only
get :authenticate_with_http_only
- assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"]
+ assert_equal "user_name=david; path=/; HttpOnly", @response.headers["Set-Cookie"]
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_multiple_cookies
get :set_multiple_cookies
assert_equal 2, @response.cookies.size
- assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"][0]
- assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1]
+ assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/", @response.headers["Set-Cookie"]
assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies)
end
@@ -96,7 +95,7 @@ class CookieTest < ActionController::TestCase
def test_expiring_cookie
get :logout
- assert_equal ["user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"]
+ assert_equal "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"]
assert_equal({"user_name" => nil}, @response.cookies)
end
@@ -117,6 +116,6 @@ class CookieTest < ActionController::TestCase
def test_delete_cookie_with_path
get :delete_cookie_with_path
- assert_equal ["user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"]
+ assert_equal "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"]
end
end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 023bf0eeaa..dd2dd7a502 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -1293,15 +1293,15 @@ class RenderTest < ActionController::TestCase
def test_head_with_symbolic_status
get :head_with_symbolic_status, :status => "ok"
- assert_equal "200 OK", @response.status
+ assert_equal 200, @response.status
assert_response :ok
get :head_with_symbolic_status, :status => "not_found"
- assert_equal "404 Not Found", @response.status
+ assert_equal 404, @response.status
assert_response :not_found
get :head_with_symbolic_status, :status => "no_content"
- assert_equal "204 No Content", @response.status
+ assert_equal 204, @response.status
assert !@response.headers.include?('Content-Length')
assert_response :no_content
@@ -1322,7 +1322,7 @@ class RenderTest < ActionController::TestCase
def test_head_with_string_status
get :head_with_string_status, :status => "404 Eat Dirt"
assert_equal 404, @response.response_code
- assert_equal "Eat Dirt", @response.message
+ assert_equal "Not Found", @response.message
assert_response :not_found
end
@@ -1590,7 +1590,7 @@ class EtagRenderTest < ActionController::TestCase
def test_render_against_etag_request_should_304_when_match
@request.if_none_match = etag_for("hello david")
get :render_hello_world_from_variable
- assert_equal "304 Not Modified", @response.status
+ assert_equal 304, @response.status
assert @response.body.empty?
end
@@ -1603,13 +1603,13 @@ class EtagRenderTest < ActionController::TestCase
def test_render_against_etag_request_should_200_when_no_match
@request.if_none_match = etag_for("hello somewhere else")
get :render_hello_world_from_variable
- assert_equal "200 OK", @response.status
+ assert_equal 200, @response.status
assert !@response.body.empty?
end
def test_render_should_not_set_etag_when_last_modified_has_been_specified
get :render_hello_world_with_last_modified_set
- assert_equal "200 OK", @response.status
+ assert_equal 200, @response.status
assert_not_nil @response.last_modified
assert_nil @response.etag
assert @response.body.present?
@@ -1623,11 +1623,11 @@ class EtagRenderTest < ActionController::TestCase
@request.if_none_match = expected_etag
get :render_hello_world_from_variable
- assert_equal "304 Not Modified", @response.status
+ assert_equal 304, @response.status
@request.if_none_match = "\"diftag\""
get :render_hello_world_from_variable
- assert_equal "200 OK", @response.status
+ assert_equal 200, @response.status
end
def render_with_404_shouldnt_have_etag
@@ -1695,7 +1695,7 @@ class LastModifiedRenderTest < ActionController::TestCase
def test_request_not_modified
@request.if_modified_since = @last_modified
get :conditional_hello
- assert_equal "304 Not Modified", @response.status
+ assert_equal 304, @response.status
assert @response.body.blank?, @response.body
assert_equal @last_modified, @response.headers['Last-Modified']
end
@@ -1710,7 +1710,7 @@ class LastModifiedRenderTest < ActionController::TestCase
def test_request_modified
@request.if_modified_since = 'Thu, 16 Jul 2008 00:00:00 GMT'
get :conditional_hello
- assert_equal "200 OK", @response.status
+ assert_equal 200, @response.status
assert !@response.body.blank?
assert_equal @last_modified, @response.headers['Last-Modified']
end
diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb
index 2e14a0a32c..6007ebef7a 100644
--- a/actionpack/test/controller/send_file_test.rb
+++ b/actionpack/test/controller/send_file_test.rb
@@ -44,12 +44,12 @@ class SendFileTest < ActionController::TestCase
response = nil
assert_nothing_raised { response = process('file') }
assert_not_nil response
- assert_kind_of Proc, response.body_parts
+ assert_kind_of Array, response.body_parts
require 'stringio'
output = StringIO.new
output.binmode
- assert_nothing_raised { response.body_parts.call(response, output) }
+ assert_nothing_raised { response.body_parts.each { |part| output << part.to_s } }
assert_equal file_data, output.string
end
@@ -149,13 +149,13 @@ class SendFileTest < ActionController::TestCase
define_method "test_send_#{method}_status" do
@controller.options = { :stream => false, :status => 500 }
assert_nothing_raised { assert_not_nil process(method) }
- assert_equal '500 Internal Server Error', @response.status
+ assert_equal 500, @response.status
end
define_method "test_default_send_#{method}_status" do
@controller.options = { :stream => false }
assert_nothing_raised { assert_not_nil process(method) }
- assert_equal ActionController::DEFAULT_RENDER_STATUS_CODE, @response.status
+ assert_equal 200, @response.status
end
end
end
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 919f9815ec..9e88188b9a 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -614,7 +614,9 @@ XML
def test_binary_content_works_with_send_file
get :test_send_file
- assert_nothing_raised(NoMethodError) { @response.binary_content }
+ assert_deprecated do
+ assert_nothing_raised(NoMethodError) { @response.binary_content }
+ end
end
protected
diff --git a/actionpack/test/template/body_parts_test.rb b/actionpack/test/template/body_parts_test.rb
index 5be8533293..e17092a452 100644
--- a/actionpack/test/template/body_parts_test.rb
+++ b/actionpack/test/template/body_parts_test.rb
@@ -16,7 +16,11 @@ class BodyPartsTest < ActionController::TestCase
def test_body_parts
get :index
- assert_equal RENDERINGS, @response.body_parts
+ pending do
+ # TestProcess buffers body_parts into body
+ # TODO: Rewrite test w/o going through process
+ assert_equal RENDERINGS, @response.body_parts
+ end
assert_equal RENDERINGS.join, @response.body
end
end
diff --git a/actionpack/test/template/output_buffer_test.rb b/actionpack/test/template/output_buffer_test.rb
index bc17f36783..3faea64db3 100644
--- a/actionpack/test/template/output_buffer_test.rb
+++ b/actionpack/test/template/output_buffer_test.rb
@@ -10,26 +10,32 @@ class OutputBufferTest < ActionController::TestCase
tests TestController
def test_flush_output_buffer
- # Start with the default body parts
- get :index
- assert_equal ['foo'], @response.body_parts
- assert_nil @controller.template.output_buffer
+ pending do
+ # TODO: This tests needs to be rewritten due
+ # The @response is not the same response object assigned
+ # to the @controller.template
- # Nil output buffer is skipped
- @controller.template.flush_output_buffer
- assert_nil @controller.template.output_buffer
- assert_equal ['foo'], @response.body_parts
+ # Start with the default body parts
+ get :index
+ assert_equal ['foo'], @response.body_parts
+ assert_nil @controller.template.output_buffer
- # Empty output buffer is skipped
- @controller.template.output_buffer = ''
- @controller.template.flush_output_buffer
- assert_equal '', @controller.template.output_buffer
- assert_equal ['foo'], @response.body_parts
+ # Nil output buffer is skipped
+ @controller.template.flush_output_buffer
+ assert_nil @controller.template.output_buffer
+ assert_equal ['foo'], @response.body_parts
- # Flushing appends the output buffer to the body parts
- @controller.template.output_buffer = 'bar'
- @controller.template.flush_output_buffer
- assert_equal '', @controller.template.output_buffer
- assert_equal ['foo', 'bar'], @response.body_parts
+ # Empty output buffer is skipped
+ @controller.template.output_buffer = ''
+ @controller.template.flush_output_buffer
+ assert_equal '', @controller.template.output_buffer
+ assert_equal ['foo'], @response.body_parts
+
+ # Flushing appends the output buffer to the body parts
+ @controller.template.output_buffer = 'bar'
+ @controller.template.flush_output_buffer
+ assert_equal '', @controller.template.output_buffer
+ assert_equal ['foo', 'bar'], @response.body_parts
+ end
end
end