1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

open_session can just return the a dup of the current context.

At this point, its entire purpose in the open_session {} case was to
delegate back to the IntegrationTest anyway.
This commit is contained in:
wycats 2010-03-22 17:04:56 -07:00
parent 1f93a46b43
commit 15c31c7639
2 changed files with 6 additions and 29 deletions

View file

@ -297,7 +297,7 @@ module ActionDispatch
# Reset the current session. This is useful for testing multiple sessions
# in a single test case.
def reset!
@integration_session = open_session
@integration_session = Integration::Session.new(app)
end
%w(get post put head delete cookies assigns
@ -323,30 +323,9 @@ module ActionDispatch
# can use this method to open multiple sessions that ought to be tested
# simultaneously.
def open_session(app = nil)
session = Integration::Session.new(app || self.app)
# 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)
extras.__send__(:define_method, name) { |*args|
delegate.send(name, *args)
}
end
dup.tap do |session|
yield session if block_given?
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
# Copy the instance variables from the current session instance into the

View file

@ -173,14 +173,12 @@ class IntegrationTestTest < Test::Unit::TestCase
end
def test_opens_new_session
@test.class.expects(:fixture_table_names).times(2).returns(['foo'])
session1 = @test.open_session { |sess| }
session2 = @test.open_session # implicit session
assert_kind_of ::ActionController::Integration::Session, session1
assert_kind_of ::ActionController::Integration::Session, session2
assert_not_equal session1, session2
assert session1.respond_to?(:assert_template), "open_session makes assert_template available"
assert session2.respond_to?(:assert_template), "open_session makes assert_template available"
assert !session1.equal?(session2)
end
# RSpec mixes Matchers (which has a #method_missing) into