Skip to content
Browse files

Add test case for ActiveRecord::ConnectionAdapters::ConnectionManagem…

…ent.

- Make sure ConnectionManagement clears connections after each call, except in tests

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent 0a8c003 commit 809409d92fa57555fe0b3a148e41d2a47a1551d2 @Manfred Manfred committed with josh Feb 25, 2009
Showing with 25 additions and 0 deletions.
  1. +25 −0 activerecord/test/cases/connection_pool_test.rb
View
25 activerecord/test/cases/connection_pool_test.rb
@@ -0,0 +1,25 @@
+require "cases/helper"
+
+class ConnectionManagementTest < ActiveRecord::TestCase
+ def setup
+ @env = {}
+ @app = stub('App')
+ @management = ActiveRecord::ConnectionAdapters::ConnectionManagement.new(@app)
+
+ @connections_cleared = false
+ ActiveRecord::Base.stubs(:clear_active_connections!).with { @connections_cleared = true }
+ end
+
+ test "clears active connections after each call" do
+ @app.expects(:call).with(@env)
+ @management.call(@env)
+ assert @connections_cleared
+ end
+
+ test "doesn't clear active connections when running in a test case" do
+ @env['rack.test'] = true
+ @app.expects(:call).with(@env)
+ @management.call(@env)
+ assert !@connections_cleared
+ end
+end

0 comments on commit 809409d

Please sign in to comment.
Something went wrong with that request. Please try again.