Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More integration testing tweaks

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3840 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 8e8b6b9e403cdeb57d0ba373bff6498dc7f9f5df 1 parent 77e2f00
@jamis jamis authored
Showing with 22 additions and 7 deletions.
  1. +22 −7 actionpack/lib/action_controller/integration_test.rb
View
29 actionpack/lib/action_controller/integration_test.rb
@@ -461,7 +461,10 @@ def reset!
%w(get post cookies assigns).each do |method|
define_method(method) do |*args|
- @integration_session.send(method, *args)
+ reset! unless @integration_session
+ returning @integration_session.send(method, *args) do
+ copy_session_variables!
+ end
end
end
@@ -479,26 +482,38 @@ def open_session
session = Integration::Session.new
# delegate the fixture accessors back to the test instance
- klass = class<<session; self; end
- tests = self
-
+ extras = Module.new { attr_accessor :delegate, :test_result }
self.class.fixture_table_names.each do |table_name|
name = table_name.tr(".", "_")
next unless respond_to?(name)
- klass.send(:define_method, name) { |*args| tests.send(name, *args) }
+ extras.send(:define_method, name) { |*args| delegate.send(name, *args) }
end
# delegate add_assertion to the test case
- klass.send(:define_method, :add_assertion) { tests.add_assertion }
+ extras.send(:define_method, :add_assertion) { test_result.add_assertion }
+ session.extend(extras)
+ session.delegate = self
+ session.test_result = @_result
yield session if block_given?
session
end
+ # Copy the instance variables from the current session instance into the
+ # test instance.
+ def copy_session_variables! #:nodoc:
+ return unless @integration_session
+ %w(controller response request).each do |var|
+ instance_variable_set("@#{var}", @integration_session.send(var))
+ end
+ end
+
# Delegate unhandled messages to the current session instance.
def method_missing(sym, *args, &block)
reset! unless @integration_session
- @integration_session.send(sym, *args, &block)
+ returning @integration_session.send(sym, *args, &block) do
+ copy_session_variables!
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.