Updated README.rdoc again
[feedcatcher.git] / vendor / rails / activerecord / test / cases / connection_test_mysql.rb
1 require "cases/helper"
2
3 class MysqlConnectionTest < ActiveRecord::TestCase
4 def setup
5 super
6 @connection = ActiveRecord::Base.connection
7 end
8
9 def test_mysql_reconnect_attribute_after_connection_with_reconnect_true
10 run_without_connection do |orig_connection|
11 ActiveRecord::Base.establish_connection(orig_connection.merge({:reconnect => true}))
12 assert ActiveRecord::Base.connection.raw_connection.reconnect
13 end
14 end
15
16 def test_mysql_reconnect_attribute_after_connection_with_reconnect_false
17 run_without_connection do |orig_connection|
18 ActiveRecord::Base.establish_connection(orig_connection.merge({:reconnect => false}))
19 assert !ActiveRecord::Base.connection.raw_connection.reconnect
20 end
21 end
22
23 def test_no_automatic_reconnection_after_timeout
24 assert @connection.active?
25 @connection.update('set @@wait_timeout=1')
26 sleep 2
27 assert !@connection.active?
28 end
29
30 def test_successful_reconnection_after_timeout_with_manual_reconnect
31 assert @connection.active?
32 @connection.update('set @@wait_timeout=1')
33 sleep 2
34 @connection.reconnect!
35 assert @connection.active?
36 end
37
38 def test_successful_reconnection_after_timeout_with_verify
39 assert @connection.active?
40 @connection.update('set @@wait_timeout=1')
41 sleep 2
42 @connection.verify!
43 assert @connection.active?
44 end
45
46 private
47
48 def run_without_connection
49 original_connection = ActiveRecord::Base.remove_connection
50 begin
51 yield original_connection
52 ensure
53 ActiveRecord::Base.establish_connection(original_connection)
54 end
55 end
56 end