Dynamically set allow_concurrency. Closes #4044.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3862 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper
2006-03-13 17:28:55 +00:00
parent 8ff4463193
commit 25fb2db409
5 changed files with 79 additions and 32 deletions

View File

@@ -9,7 +9,7 @@ class MethodScopingTest < Test::Unit::TestCase
def test_set_conditions
Developer.with_scope(:find => { :conditions => 'just a test...' }) do
assert_equal 'just a test...', Thread.current[:scoped_methods][Developer][-1][:find][:conditions]
assert_equal 'just a test...', Developer.send(:current_scoped_methods)[:find][:conditions]
end
end
@@ -64,7 +64,7 @@ class MethodScopingTest < Test::Unit::TestCase
new_comment = nil
VerySpecialComment.with_scope(:create => { :post_id => 1 }) do
assert_equal({ :post_id => 1 }, Thread.current[:scoped_methods][VerySpecialComment][-1][:create])
assert_equal({ :post_id => 1 }, VerySpecialComment.send(:current_scoped_methods)[:create])
new_comment = VerySpecialComment.create :body => "Wonderful world"
end
@@ -123,7 +123,7 @@ class NestedScopingTest < Test::Unit::TestCase
Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
Developer.with_exclusive_scope(:find => { :conditions => "name = 'Jamis'" }) do
assert_equal({:find => { :conditions => "name = 'Jamis'" }}, Developer.instance_eval('current_scoped_methods'))
assert_equal({:find => { :conditions => "name = 'Jamis'" }}, Thread.current[:scoped_methods][Developer][-1])
assert_equal({:find => { :conditions => "name = 'Jamis'" }}, Developer.send(:scoped_methods)[-1])
end
end
end

View File

@@ -9,6 +9,16 @@ class ThreadedConnectionsTest < Test::Unit::TestCase
def setup
@connection = ActiveRecord::Base.remove_connection
@connections = []
@allow_concurrency = ActiveRecord::Base.allow_concurrency
end
def teardown
# clear the connection cache
ActiveRecord::Base.send(:clear_all_cached_connections!)
# set allow_concurrency to saved value
ActiveRecord::Base.allow_concurrency = @allow_concurrency
# reestablish old connection
ActiveRecord::Base.establish_connection(@connection)
end
def gather_connections(use_threaded_connections)