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

Use with_connection instead of calling release_connection directly #340

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @get-bridge/arcanine
29 changes: 29 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#### JIRA

#### Changes

-

#### Checklist
- [ ] Feature Flag Required
- [ ] Bug

#### Test plan

- [ ] Walk-through
- [ ] Peer review
- [ ] Inspection
- Detailed steps and prerequisites for validating the change:
- <!-- Replace this with the bullet points about the steps how to execute the test -->

#### Risk Analysis - the risk of change is evaluated

- [ ] Low - Majority of the changes are low risk which doesn’t require extra testing, only code review by 1 reviewer
- [ ] 1 reviewer
- [ ] Medium - Some portion of changes are medium risk which need peer testing and review by 2 reviewers
- [ ] 2 reviewers
- [ ] peer testing
- [ ] High - A very few breaking changes are high risk and need very throughout testing and review and also coordinated release process.
- [ ] 2 reviewers
- [ ] peer testing
- [ ] coordinated release
32 changes: 16 additions & 16 deletions lib/closure_tree/has_closure_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ def has_closure_tree(options = {})
:with_advisory_lock
)

class_attribute :_ct
self._ct = ClosureTree::Support.new(self, options)
connection_pool.with_connection {
class_attribute :_ct
self._ct = ClosureTree::Support.new(self, options)

# Auto-inject the hierarchy table
# See https://github.com/patshaughnessy/class_factory/blob/master/lib/class_factory/class_factory.rb
class_attribute :hierarchy_class
self.hierarchy_class = _ct.hierarchy_class_for_model
# Auto-inject the hierarchy table
# See https://github.com/patshaughnessy/class_factory/blob/master/lib/class_factory/class_factory.rb
class_attribute :hierarchy_class
self.hierarchy_class = _ct.hierarchy_class_for_model

# tests fail if you include Model before HierarchyMaintenance wtf
include ClosureTree::HierarchyMaintenance
include ClosureTree::Model
include ClosureTree::Finders
include ClosureTree::HashTree
include ClosureTree::Digraphs
# tests fail if you include Model before HierarchyMaintenance wtf
include ClosureTree::HierarchyMaintenance
include ClosureTree::Model
include ClosureTree::Finders
include ClosureTree::HashTree
include ClosureTree::Digraphs

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

connection_pool.release_connection
include ClosureTree::DeterministicOrdering if _ct.order_option?
include ClosureTree::NumericDeterministicOrdering if _ct.order_is_numeric?
}
rescue StandardError => e
raise e unless ClosureTree.configuration.database_less
end
Expand Down
2 changes: 1 addition & 1 deletion lib/closure_tree/hierarchy_maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def cleanup!

[:descendant_id, :ancestor_id].each do |foreign_key|
alias_name = foreign_key.to_s.split('_').first + "s"
alias_table = Arel::Table.new(table_name).alias(alias_name)
alias_table = Arel::Table.new(table_name, type_caster: type_caster).alias(alias_name)
arel_join = hierarchy_table.join(alias_table, Arel::Nodes::OuterJoin)
.on(alias_table[primary_key].eq(hierarchy_table[foreign_key]))
.join_sources
Expand Down
5 changes: 5 additions & 0 deletions spec/pool_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require 'spec_helper'

describe 'Configuration' do
before(:each) do
# Make sure we start up with no active connection
ActiveRecord::Base.connection_pool.release_connection
end

it 'returns connection to the pool after has_closure_tree setup' do
class TypeDuplicate < ActiveRecord::Base
self.table_name = "namespace_type#{table_name_suffix}"
Expand Down