Skip to content

Commit

Permalink
Merge pull request ClosureTree#263 from Envek/pool-checkin
Browse files Browse the repository at this point in the history
Return database connection into pool after configuration
  • Loading branch information
mceachen authored Apr 14, 2017
2 parents f03ebd7 + 4ed2ea9 commit 0f405ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/closure_tree/has_closure_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def has_closure_tree(options = {})

include ClosureTree::DeterministicOrdering if _ct.order_option?
include ClosureTree::NumericDeterministicOrdering if _ct.order_is_numeric?

connection_pool.release_connection
rescue StandardError => e
raise e unless ClosureTree.configuration.database_less
end
Expand Down
2 changes: 2 additions & 0 deletions lib/closure_tree/has_closure_tree_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def has_closure_tree_root(assoc_name, options = {})

@closure_tree_roots[assoc_name][assoc_map] = root
end

connection_pool.release_connection
end
end
end
27 changes: 27 additions & 0 deletions spec/pool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe 'Configuration' do
it 'returns connection to the pool after has_closure_tree setup' do
class TypeDuplicate < ActiveRecord::Base
self.table_name = "namespace_type#{table_name_suffix}"
has_closure_tree
end
expect(ActiveRecord::Base.connection_pool.active_connection?).to be_falsey # +false+ in AR 4, +nil+ in AR 5
end

it 'returns connection to the pool after has_closure_tree setup with order' do
class MetalDuplicate < ActiveRecord::Base
self.table_name = "#{table_name_prefix}metal#{table_name_suffix}"
has_closure_tree order: 'sort_order', name_column: 'value'
end
expect(ActiveRecord::Base.connection_pool.active_connection?).to be_falsey
end

it 'returns connection to the pool after has_closure_tree_root setup' do
class GroupDuplicate < ActiveRecord::Base
self.table_name = "#{table_name_prefix}group#{table_name_suffix}"
has_closure_tree_root :root_user
end
expect(ActiveRecord::Base.connection_pool.active_connection?).to be_falsey
end
end

0 comments on commit 0f405ca

Please sign in to comment.