Skip to content

Commit

Permalink
ActiveRecord 7.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
wollistik committed Sep 2, 2024
1 parent 583ed2b commit f8f76d8
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 109 deletions.
30 changes: 5 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
gemfile: [ar_52, ar_60, ar_61, ar_70, ar_next]
exclude:
- ruby-version: '3.2'
gemfile: ar_52
- ruby-version: '3.2'
gemfile: ar_60
- ruby-version: '3.2'
gemfile: ar_61
- ruby-version: '3.1'
gemfile: ar_52
- ruby-version: '3.1'
gemfile: ar_60
- ruby-version: '3.1'
gemfile: ar_61
- ruby-version: '3.0'
gemfile: ar_52
- ruby-version: '2.6'
gemfile: ar_next
- ruby-version: '2.6'
gemfile: ar_70
- ruby-version: '2.5'
gemfile: ar_next
- ruby-version: '2.5'
gemfile: ar_70
ruby-version: ['3.1', '3.2', '3.3']
gemfile: [ar_70, ar_71, ar_72, ar_next]
# exclude:
# - ruby-version: '3.2'
# gemfile: ar_60
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
uses: ruby/setup-ruby@v1
# uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
with:
ruby-version: 2.7
ruby-version: 3.1
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run rubocop
run: bundle exec rubocop
4 changes: 2 additions & 2 deletions .github/workflows/rubygem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
contents: read

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.1
- run: bundle install
- name: Publish to RubyGems
env:
Expand Down
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ require:
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1
NewCops: enable
SuggestExtensions: false

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec

Gemspec/RequireMFA:
Enabled: false

Expand All @@ -24,6 +27,9 @@ RSpec/NestedGroups:
Style/Alias:
EnforcedStyle: prefer_alias

Style/Documentation:
Enabled: false

Style/FrozenStringLiteralComment:
Exclude:
- 'gemfiles/**/*'
Expand Down
23 changes: 9 additions & 14 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
# frozen_string_literal: true

appraise 'ar-52' do
gem 'activerecord', '~> 5.2.0'
gem 'activesupport', '~> 5.2.0'
end

appraise 'ar-60' do
gem 'activerecord', '~> 6.0.0'
gem 'activesupport', '~> 6.0.0'
appraise 'ar-70' do
gem 'activerecord', '~> 7.0'
gem 'activesupport', '~> 7.0'
end

appraise 'ar-61' do
gem 'activerecord', '~> 6.1.0'
gem 'activesupport', '~> 6.1.0'
appraise 'ar-71' do
gem 'activerecord', '~> 7.1'
gem 'activesupport', '~> 7.1'
end

appraise 'ar-70' do
gem 'activerecord', '~> 7.0'
gem 'activesupport', '~> 7.0'
appraise 'ar-72' do
gem 'activerecord', '~> 7.2'
gem 'activesupport', '~> 7.2'
end

appraise 'ar-next' do
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Version 4.0.0
- ADD: Support for Rails 7.2
- BREAKING: Dropped support for Rails < 7
- BREAKING: Dropped support old Rubies < 3.1

### Version 3.5.0
- Added :dependent option for setting explicit deletion behaviour (issue #31)
- Added automatic cycle detection when supported (currently only PostgresSQL 14+) (issue #22)
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ Luckily, there is already a SQL standard that makes it very easy to retrieve dat

## Supported environments
ActsAsRecursiveTree currently supports following ActiveRecord versions and is tested for compatibility:
* ActiveRecord 5.2.x
* ActiveRecord 6.0.x
* ActiveRecord 6.1.x
* ActiveRecord 7.0.x
* ActiveRecord 7.1.x
* ActiveRecord 7.2.x
* ActiveRecord NEXT (from git)

## Supported Rubies
ActsAsRecursiveTree is tested with following rubies:
* MRuby 2.5
* MRuby 2.6
* MRuby 2.7
* MRuby 3.0
* MRuby 3.1
* MRuby 3.2
* MRuby 3.3

Other Ruby implementations are not tested, but should also work.

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ task default: [:spec]
desc 'Deletes temporary files'
task :clean_tmp_files do
%w[db.log test.sqlite3].each do |file|
File.delete(file) if File.exist?(file)
FileUtils.rm_f(file)
end
end
23 changes: 11 additions & 12 deletions acts_as_recursive_tree.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ Gem::Specification.new do |spec|
'bug_tracker_uri' => 'https://github.com/1and1/acts_as_recursive_tree/issues',
'changelog_uri' => 'https://github.com/1and1/acts_as_recursive_tree/blob/main/CHANGELOG.md'
}
spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = '>= 3.1.0'
spec.files = `git ls-files -z`.split("\x0")
spec.test_files = spec.files.grep(%r{^spec/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'activerecord', '>= 5.2.0', '< 8'
spec.add_runtime_dependency 'activesupport', '>= 5.2.0', '< 8'
spec.add_runtime_dependency 'zeitwerk', '>= 2.4'
spec.add_dependency 'activerecord', '>= 7.0.0', '< 8'
spec.add_dependency 'activesupport', '>= 7.0.0', '< 8'
spec.add_dependency 'zeitwerk', '>= 2.4'

spec.add_development_dependency 'appraisal', '~> 2.4'
spec.add_development_dependency 'database_cleaner-active_record', '~> 2.1'
spec.add_development_dependency 'appraisal', '~> 2.5'
spec.add_development_dependency 'database_cleaner-active_record', '~> 2.2'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec-rails', '>= 3.5'
spec.add_development_dependency 'rubocop', '~> 1.23.0'
spec.add_development_dependency 'rubocop-rails', '~> 2.12.0'
spec.add_development_dependency 'rubocop-rspec', '~> 2.6.0'
spec.add_development_dependency 'rspec-rails', '>= 6.1'
spec.add_development_dependency 'rubocop', '~> 1.66.0'
spec.add_development_dependency 'rubocop-rails', '~> 2.26.0'
spec.add_development_dependency 'rubocop-rspec', '~> 3.0.4'

spec.add_development_dependency 'sqlite3', '~> 1.3'
spec.add_development_dependency 'sqlite3', '~> 2.0'
end
8 changes: 0 additions & 8 deletions gemfiles/ar_61.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions gemfiles/ar_52.gemfile → gemfiles/ar_71.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "~> 5.2.0"
gem "activesupport", "~> 5.2.0"
gem "activerecord", "~> 7.1"
gem "activesupport", "~> 7.1"

gemspec path: "../"
4 changes: 2 additions & 2 deletions gemfiles/ar_60.gemfile → gemfiles/ar_72.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "activerecord", "~> 6.0.0"
gem "activesupport", "~> 6.0.0"
gem "activerecord", "~> 7.2"
gem "activesupport", "~> 7.2"

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/acts_as_recursive_tree/acts_macro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def recursive_tree(parent_key: :parent_id, parent_type_column: nil, dependent: n
model_class: self,
parent_key: parent_key.to_sym,
parent_type_column: parent_type_column.try(:to_sym),
dependent: dependent
dependent:
)

include ActsAsRecursiveTree::Model
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_recursive_tree/builders/ancestors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Builders
class Ancestors < RelationBuilder
self.traversal_strategy = ActsAsRecursiveTree::Builders::Strategies::Ancestor

def get_query_options(&block)
def get_query_options(&)
opts = super
opts.ensure_ordering!
opts
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_recursive_tree/builders/leaves.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_select_manger(column = nil)
select_manager
end

def get_query_options(&_block)
def get_query_options(&)
# do not allow any custom options
ActsAsRecursiveTree::Options::QueryOptions.new
end
Expand Down
6 changes: 3 additions & 3 deletions lib/acts_as_recursive_tree/builders/relation_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Builders
#
class RelationBuilder
def self.build(klass, ids, exclude_ids: false, &block)
new(klass, ids, exclude_ids: exclude_ids, &block).build
new(klass, ids, exclude_ids:, &block).build
end

class_attribute :traversal_strategy, instance_writer: false
Expand Down Expand Up @@ -48,8 +48,8 @@ def config
# Subclasses may override this method to provide sane defaults.
#
# @return [ActsAsRecursiveTree::Options::QueryOptions] the new QueryOptions instance
def get_query_options(&block)
ActsAsRecursiveTree::Options::QueryOptions.from(&block)
def get_query_options(&)
ActsAsRecursiveTree::Options::QueryOptions.from(&)
end

def base_table
Expand Down
40 changes: 20 additions & 20 deletions lib/acts_as_recursive_tree/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ module Model
#
# subchild1.ancestors # => [child1, root]
#
def ancestors(&block)
base_class.ancestors_of(self, &block)
def ancestors(&)
base_class.ancestors_of(self, &)
end

# Returns ancestors and current node itself.
#
# subchild1.self_and_ancestors # => [subchild1, child1, root]
#
def self_and_ancestors(&block)
base_class.self_and_ancestors_of(self, &block)
def self_and_ancestors(&)
base_class.self_and_ancestors_of(self, &)
end

##
# Returns list of descendants, starting from current node, not including current node.
#
# root.descendants # => [child1, child2, subchild1, subchild2, subchild3, subchild4]
#
def descendants(&block)
base_class.descendants_of(self, &block)
def descendants(&)
base_class.descendants_of(self, &)
end

##
# Returns list of descendants, starting from current node, including current node.
#
# root.self_and_descendants # => [root, child1, child2, subchild1, subchild2, subchild3, subchild4]
#
def self_and_descendants(&block)
base_class.self_and_descendants_of(self, &block)
def self_and_descendants(&)
base_class.self_and_descendants_of(self, &)
end

##
Expand All @@ -50,7 +50,7 @@ def root
#
# subchild1.siblings # => [subchild2]
def siblings
self_and_siblings.where.not(id: id)
self_and_siblings.where.not(id:)
end

##
Expand Down Expand Up @@ -97,7 +97,7 @@ def leaf?
# @param includes [Array|Hash] pass the same arguments that should be passed to the #includes() method.
#
def preload_tree(includes: nil)
ActsAsRecursiveTree::Preloaders::Descendants.new(self, includes: includes).preload!
ActsAsRecursiveTree::Preloaders::Descendants.new(self, includes:).preload!
true
end

Expand All @@ -108,28 +108,28 @@ def base_class
private :base_class

module ClassMethods
def self_and_ancestors_of(ids, &block)
ActsAsRecursiveTree::Builders::Ancestors.build(self, ids, &block)
def self_and_ancestors_of(ids, &)
ActsAsRecursiveTree::Builders::Ancestors.build(self, ids, &)
end

def ancestors_of(ids, &block)
ActsAsRecursiveTree::Builders::Ancestors.build(self, ids, exclude_ids: true, &block)
def ancestors_of(ids, &)
ActsAsRecursiveTree::Builders::Ancestors.build(self, ids, exclude_ids: true, &)
end

def roots_of(ids)
self_and_ancestors_of(ids).roots
end

def self_and_descendants_of(ids, &block)
ActsAsRecursiveTree::Builders::Descendants.build(self, ids, &block)
def self_and_descendants_of(ids, &)
ActsAsRecursiveTree::Builders::Descendants.build(self, ids, &)
end

def descendants_of(ids, &block)
ActsAsRecursiveTree::Builders::Descendants.build(self, ids, exclude_ids: true, &block)
def descendants_of(ids, &)
ActsAsRecursiveTree::Builders::Descendants.build(self, ids, exclude_ids: true, &)
end

def leaves_of(ids, &block)
ActsAsRecursiveTree::Builders::Leaves.build(self, ids, &block)
def leaves_of(ids, &)
ActsAsRecursiveTree::Builders::Leaves.build(self, ids, &)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_recursive_tree/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActsAsRecursiveTree
VERSION = '3.5.0'
VERSION = '4.0.0'
end
2 changes: 1 addition & 1 deletion spec/db/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

ActiveRecord::Migration.verbose = false

ActiveRecord::Base.configurations = YAML.safe_load(File.read("#{database_folder}/database.yml"))
ActiveRecord::Base.configurations = YAML.safe_load_file("#{database_folder}/database.yml")

if ActiveRecord.version >= Gem::Version.new('6.1.0')
config = ActiveRecord::Base.configurations.configs_for env_name: database_adapter, name: 'primary'
Expand Down
Loading

0 comments on commit f8f76d8

Please sign in to comment.