From da8046337dd7351208847a46739133b80d3529db Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 14 Dec 2025 03:21:58 +0100 Subject: [PATCH] fix: improve api usage release-as: 9.5.0 --- .github/workflows/ci.yml | 24 +++++++++-------------- lib/closure_tree/arel_helpers.rb | 2 +- lib/closure_tree/hierarchy_maintenance.rb | 4 ++-- test/closure_tree/adopt_test.rb | 3 --- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d87cfaf..63b84ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -46,6 +53,7 @@ jobs: ruby: - '3.4' rails: + - '7.2' - '8.0' - '8.1.1' @@ -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 \ No newline at end of file + bundle exec rake test diff --git a/lib/closure_tree/arel_helpers.rb b/lib/closure_tree/arel_helpers.rb index 74bb6b2..64886e7 100644 --- a/lib/closure_tree/arel_helpers.rb +++ b/lib/closure_tree/arel_helpers.rb @@ -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 diff --git a/lib/closure_tree/hierarchy_maintenance.rb b/lib/closure_tree/hierarchy_maintenance.rb index 9b41859..825181a 100644 --- a/lib/closure_tree/hierarchy_maintenance.rb +++ b/lib/closure_tree/hierarchy_maintenance.rb @@ -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) diff --git a/test/closure_tree/adopt_test.rb b/test/closure_tree/adopt_test.rb index 8056dcd..0a2a5ee 100644 --- a/test/closure_tree/adopt_test.rb +++ b/test/closure_tree/adopt_test.rb @@ -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 @@ -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