Permalink
Browse files

Leased connections return false on second lease

  • Loading branch information...
tenderlove committed Nov 29, 2011
1 parent 9bf8bf8 commit 134cc8f9398a9a67b80f3cc26651dcc5c073416c
@@ -73,8 +73,10 @@ def initialize(connection, logger = nil) #:nodoc:
def lease
synchronize do
- @in_use = true
- @last_use = Time.now
+ unless in_use
+ @in_use = true
+ @last_use = Time.now
+ end
end
end
@@ -3,14 +3,23 @@
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

0 comments on commit 134cc8f

Please sign in to comment.