Skip to content
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
24 changes: 9 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
RAILS_VERSION: ${{ matrix.rails }}
RAILS_ENV: test
DATABASE_URL_PG: postgres://postgres:postgres@127.0.0.1:5432/closure_tree_test
DATABASE_URL_MYSQL: mysql2://root:root@127.0.0.1:3306/closure_tree_test
DATABASE_URL_SQLITE3: 'sqlite3::memory:'
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}

services:
postgres:
Expand Down Expand Up @@ -46,6 +53,7 @@ jobs:
ruby:
- '3.4'
rails:
- '7.2'
- '8.0'
- '8.1.1'

Expand All @@ -59,26 +67,12 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
rubygems: latest
env:
RAILS_VERSION: ${{ matrix.rails }}
BUNDLE_GEMFILE: ${{ github.workspace }}/Gemfile

- name: Setup databases
env:
RAILS_ENV: test
DATABASE_URL_PG: postgres://postgres:postgres@127.0.0.1:5432/closure_tree_test
DATABASE_URL_MYSQL: mysql2://root:root@127.0.0.1:3306/closure_tree_test
DATABASE_URL_SQLITE3: 'sqlite3::memory:'
run: |
cd test/dummy
bundle exec rails db:setup_all

- name: Run tests
env:
RAILS_ENV: test
DATABASE_URL_PG: postgres://postgres:postgres@127.0.0.1:5432/closure_tree_test
DATABASE_URL_MYSQL: mysql2://root:root@127.0.0.1:3306/closure_tree_test
DATABASE_URL_SQLITE3: 'sqlite3::memory:'
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
run: |
bundle exec rake test
bundle exec rake test
2 changes: 1 addition & 1 deletion lib/closure_tree/arel_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def build_hierarchy_delete_query(hierarchy_table, id)
# This ensures proper quoting for the specific database adapter (MySQL uses backticks, PostgreSQL uses double quotes)
def to_sql_with_connection(arel_manager)
collector = Arel::Collectors::SQLString.new
visitor = connection.send(:arel_visitor)
visitor = connection.visitor
visitor.accept(arel_manager.ast, collector).value
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/closure_tree/hierarchy_maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def _ct_after_save

def _ct_before_destroy
_ct.with_advisory_lock do
adopt_children_to_grandparent if _ct.options[:dependent] == :adopt
_ct_adopt_children_to_grandparent if _ct.options[:dependent] == :adopt
delete_hierarchy_references
self.class.find(id).children.find_each(&:rebuild!) if _ct.options[:dependent] == :nullify
end
true # don't prevent destruction
end

def adopt_children_to_grandparent
private def _ct_adopt_children_to_grandparent
grandparent_id = read_attribute(_ct.parent_column_name)
children_ids = self.class.where(_ct.parent_column_name => id).pluck(:id)

Expand Down
3 changes: 0 additions & 3 deletions test/closure_tree/adopt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def run_adopt_tests_for(model_class)
assert_equal p2, p3.parent

hierarchy = model_class.hierarchy_class
hierarchy.where(ancestor_id: p2.id).count
hierarchy.where(descendant_id: p3.id).count

# Destroy p1 (root node)
p1.destroy
Expand Down Expand Up @@ -210,7 +208,6 @@ def run_adopt_tests_for(model_class)
leaf = model_class.create!(name: 'leaf', parent: p2)

hierarchy = model_class.hierarchy_class
hierarchy.count

# Destroy leaf (has no children)
leaf.destroy
Expand Down