aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG4
-rw-r--r--actionpack/lib/action_controller/test_process.rb11
-rw-r--r--actionpack/test/controller/test_test.rb17
3 files changed, 26 insertions, 6 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 63e69accbc..5d3765aaba 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Use raise instead of assert_not_nil in Test::Unit::TestCase#process to ensure that the test variables (controller, request, response) have been set
+
* Make sure assigns are built for every request when testing #1866
* Allow remote_addr to be queried on TestRequest #1668
@@ -7,7 +9,7 @@
* Fixed bug when a partial render was passing a local with the same name as the partial
* Improved performance of test app req/sec with ~10% refactoring the render method #1823 [Stefan Kaes]
-
+
* Improved performance of test app req/sec with 5-30% through a series of Action Pack optimizations #1811 [Stefan Kaes]
* Changed caching/expiration/hit to report using the DEBUG log level and errors to use the ERROR log level instead of both using INFO
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index 581b08d659..5c34e9fa6d 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -269,13 +269,14 @@ module Test
private
# execute the request and set/volley the response
def process(action, parameters = nil, session = nil, flash = nil)
- @request.recycle!
-
- # Sanity check for required instance variables so we can give an understandable error message.
+ # Sanity check for required instance variables so we can give an
+ # understandable error message.
%w(controller request response).each do |iv_name|
- assert_not_nil instance_variable_get("@#{iv_name}"), "@#{iv_name} is nil: make sure you set it in your test's setup method."
+ raise "@#{iv_name} is nil: make sure you set it in your test's setup method." if instance_variable_get("@#{iv_name}").nil?
end
+ @request.recycle!
+
@html_document = nil
@request.env['REQUEST_METHOD'] ||= "GET"
@request.action = action.to_s
@@ -293,7 +294,7 @@ module Test
%w( get post put delete head ).each do |method|
class_eval <<-EOV
def #{method}(action, parameters = nil, session = nil, flash = nil)
- @request.env['REQUEST_METHOD'] = "#{method.upcase}"
+ @request.env['REQUEST_METHOD'] = "#{method.upcase}" if @request
process(action, parameters, session, flash)
end
EOV
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 570f92e6e4..fff1393872 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -177,4 +177,21 @@ HTML
get :test_remote_addr
assert_equal "192.0.0.1", @response.body
end
+
+ %w(controller response request).each do |variable|
+ %w(get post put delete head process).each do |method|
+ define_method("test_#{variable}_missing_for_#{method}_raises_error") do
+ remove_instance_variable "@#{variable}"
+ begin
+ send(method, :test_remote_addr)
+ assert false, "expected RuntimeError, got nothing"
+ rescue RuntimeError => error
+ assert true
+ assert_match %r{@#{variable} is nil}, error.message
+ rescue => error
+ assert false, "expected RuntimeError, got #{error.class}"
+ end
+ end
+ end
+ end
end