Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return database connection into pool after configuration #263

Merged
merged 1 commit into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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