diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-29 13:15:20 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-11-29 14:02:58 -0800 |
commit | 134cc8f9398a9a67b80f3cc26651dcc5c073416c (patch) | |
tree | 68e3d5d2fc7bc831700466951f8ffce86e75ec4f | |
parent | 9bf8bf82b9d8614d9c7ccc31892887f6a79ce2f5 (diff) | |
download | rails-134cc8f9398a9a67b80f3cc26651dcc5c073416c.tar.gz rails-134cc8f9398a9a67b80f3cc26651dcc5c073416c.tar.bz2 rails-134cc8f9398a9a67b80f3cc26651dcc5c073416c.zip |
Leased connections return false on second lease
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/abstract_adapter_test.rb | 13 |
2 files changed, 15 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 4a9653c08c..deb24fd393 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -73,8 +73,10 @@ module ActiveRecord def lease synchronize do - @in_use = true - @last_use = Time.now + unless in_use + @in_use = true + @last_use = Time.now + end end end diff --git a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb index ef6a57d328..b2e747c507 100644 --- a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb +++ b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb @@ -3,14 +3,23 @@ require "cases/helper" module ActiveRecord module ConnectionAdapters class AbstractAdapterTest < ActiveRecord::TestCase - def test_in_use? - adapter = AbstractAdapter.new nil, nil + attr_reader :adapter + + def setup + @adapter = AbstractAdapter.new nil, nil + end + def test_in_use? # FIXME: change to refute in Rails 4.0 / mt assert !adapter.in_use?, 'adapter is not in use' assert adapter.lease, 'lease adapter' assert adapter.in_use?, 'adapter is in use' end + + def test_lease_twice + assert adapter.lease, 'should lease adapter' + assert !adapter.lease, 'should not lease adapter' + end end end end |