aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_management_test.rb
blob: c5511673acb2f032a2d6b13815736e8ab4f800ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require "cases/helper"

module ActiveRecord
  module ConnectionAdapters
    class ConnectionManagementTest < ActiveRecord::TestCase
      def setup
        @env = {}
        @app = stub('App')
        @management = 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
  end
end