diff options
author | Dov Murik <dov.murik@gmail.com> | 2009-01-26 16:10:00 +0200 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2009-01-27 09:55:25 +1300 |
commit | 5fe6635e05a18b312c47fe6bbbaf88fd62e7703d (patch) | |
tree | db3f0fd697d8a73e7cfd0b51e0826372c66f82ec /activerecord/test/cases | |
parent | 57f0b859004698a38d6aa7d5cebc00de3fcb346d (diff) | |
download | rails-5fe6635e05a18b312c47fe6bbbaf88fd62e7703d.tar.gz rails-5fe6635e05a18b312c47fe6bbbaf88fd62e7703d.tar.bz2 rails-5fe6635e05a18b312c47fe6bbbaf88fd62e7703d.zip |
Mysql#reconnect is set according to the 'reconnect' key in the connection spec.
The 'reconenct' boolean option is read from the connection specification
and is used to set the reconnect attribute of Mysql. The default is
false in order not to change existing application behaviour.
Also, reconnect is set AFTER real_connect is called, so its value sticks
(the mysql gem sets reconnect to false inside real_connect).
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1797 state:committed]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/connection_test_mysql.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_test_mysql.rb b/activerecord/test/cases/connection_test_mysql.rb index 40ddcf5420..f79ee2f1f7 100644 --- a/activerecord/test/cases/connection_test_mysql.rb +++ b/activerecord/test/cases/connection_test_mysql.rb @@ -2,9 +2,24 @@ require "cases/helper" class MysqlConnectionTest < ActiveRecord::TestCase def setup + super @connection = ActiveRecord::Base.connection end + def test_mysql_reconnect_attribute_after_connection_with_reconnect_true + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.merge({:reconnect => true})) + assert ActiveRecord::Base.connection.raw_connection.reconnect + end + end + + def test_mysql_reconnect_attribute_after_connection_with_reconnect_false + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.merge({:reconnect => false})) + assert !ActiveRecord::Base.connection.raw_connection.reconnect + end + end + def test_no_automatic_reconnection_after_timeout assert @connection.active? @connection.update('set @@wait_timeout=1') @@ -27,4 +42,15 @@ class MysqlConnectionTest < ActiveRecord::TestCase @connection.verify! assert @connection.active? end + + private + + def run_without_connection + original_connection = ActiveRecord::Base.remove_connection + begin + yield original_connection + ensure + ActiveRecord::Base.establish_connection(original_connection) + end + end end |