instance method
open_session
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
open_session(application = nil)
Open a new session instance. If a block is given, the new session is yielded to the block before being returned.
session = open_session do |sess| sess.extend(CustomAssertions) end
By default, a single session is automatically created for you, but you can use this method to open multiple sessions that ought to be tested simultaneously.
Parameters
-
applicationopt = nil
Source
# File actionpack/lib/action_controller/integration.rb, line 531
def open_session(application = nil)
session = Integration::Session.new(application)
# delegate the fixture accessors back to the test instance
extras = Module.new { attr_accessor :delegate, :test_result }
if self.class.respond_to?(:fixture_table_names)
self.class.fixture_table_names.each do |table_name|
name = table_name.tr(".", "_")
next unless respond_to?(name, true)
extras.__send__(:define_method, name) { |*args|
delegate.send(name, *args)
}
end
end
# delegate add_assertion to the test case
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
Defined in actionpack/lib/action_controller/integration.rb line 531
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::Integration::Runner