diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e15e09..33437dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 57fce48..46ee2cc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.github/workflows/rubygem.yml b/.github/workflows/rubygem.yml index 028db84..dd1c6fb 100644 --- a/.github/workflows/rubygem.yml +++ b/.github/workflows/rubygem.yml @@ -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: diff --git a/.rubocop.yml b/.rubocop.yml index b5b2d3a..0c85b0c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 @@ -24,6 +27,9 @@ RSpec/NestedGroups: Style/Alias: EnforcedStyle: prefer_alias +Style/Documentation: + Enabled: false + Style/FrozenStringLiteralComment: Exclude: - 'gemfiles/**/*' diff --git a/Appraisals b/Appraisals index d744c1e..22e834b 100644 --- a/Appraisals +++ b/Appraisals @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index bd326be..0322c00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 2b63ace..ea319ce 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Rakefile b/Rakefile index b7645a1..2aa5b35 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/acts_as_recursive_tree.gemspec b/acts_as_recursive_tree.gemspec index 29a1528..1ec6034 100644 --- a/acts_as_recursive_tree.gemspec +++ b/acts_as_recursive_tree.gemspec @@ -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 diff --git a/gemfiles/ar_61.gemfile b/gemfiles/ar_61.gemfile deleted file mode 100644 index 43affbe..0000000 --- a/gemfiles/ar_61.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "activerecord", "~> 6.1.0" -gem "activesupport", "~> 6.1.0" - -gemspec path: "../" diff --git a/gemfiles/ar_52.gemfile b/gemfiles/ar_71.gemfile similarity index 59% rename from gemfiles/ar_52.gemfile rename to gemfiles/ar_71.gemfile index 44ff64e..d490cfb 100644 --- a/gemfiles/ar_52.gemfile +++ b/gemfiles/ar_71.gemfile @@ -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: "../" diff --git a/gemfiles/ar_60.gemfile b/gemfiles/ar_72.gemfile similarity index 59% rename from gemfiles/ar_60.gemfile rename to gemfiles/ar_72.gemfile index 16ac8a2..9341e47 100644 --- a/gemfiles/ar_60.gemfile +++ b/gemfiles/ar_72.gemfile @@ -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: "../" diff --git a/lib/acts_as_recursive_tree/acts_macro.rb b/lib/acts_as_recursive_tree/acts_macro.rb index 9a094f6..0a321f1 100644 --- a/lib/acts_as_recursive_tree/acts_macro.rb +++ b/lib/acts_as_recursive_tree/acts_macro.rb @@ -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 diff --git a/lib/acts_as_recursive_tree/builders/ancestors.rb b/lib/acts_as_recursive_tree/builders/ancestors.rb index a53ff38..690b037 100644 --- a/lib/acts_as_recursive_tree/builders/ancestors.rb +++ b/lib/acts_as_recursive_tree/builders/ancestors.rb @@ -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 diff --git a/lib/acts_as_recursive_tree/builders/leaves.rb b/lib/acts_as_recursive_tree/builders/leaves.rb index 83b31f9..0b2a0d3 100644 --- a/lib/acts_as_recursive_tree/builders/leaves.rb +++ b/lib/acts_as_recursive_tree/builders/leaves.rb @@ -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 diff --git a/lib/acts_as_recursive_tree/builders/relation_builder.rb b/lib/acts_as_recursive_tree/builders/relation_builder.rb index 663975d..38714c1 100644 --- a/lib/acts_as_recursive_tree/builders/relation_builder.rb +++ b/lib/acts_as_recursive_tree/builders/relation_builder.rb @@ -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 @@ -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 diff --git a/lib/acts_as_recursive_tree/model.rb b/lib/acts_as_recursive_tree/model.rb index 41b53f9..2f3363d 100644 --- a/lib/acts_as_recursive_tree/model.rb +++ b/lib/acts_as_recursive_tree/model.rb @@ -9,16 +9,16 @@ 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 ## @@ -26,8 +26,8 @@ def self_and_ancestors(&block) # # 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 ## @@ -35,8 +35,8 @@ def descendants(&block) # # 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 ## @@ -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 ## @@ -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 @@ -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 diff --git a/lib/acts_as_recursive_tree/version.rb b/lib/acts_as_recursive_tree/version.rb index 70c73cd..50201d1 100644 --- a/lib/acts_as_recursive_tree/version.rb +++ b/lib/acts_as_recursive_tree/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ActsAsRecursiveTree - VERSION = '3.5.0' + VERSION = '4.0.0' end diff --git a/spec/db/database.rb b/spec/db/database.rb index f0ce625..b7b95a5 100644 --- a/spec/db/database.rb +++ b/spec/db/database.rb @@ -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' diff --git a/spec/db/models.rb b/spec/db/models.rb index a90ee91..f189f07 100644 --- a/spec/db/models.rb +++ b/spec/db/models.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # Base test class -class ApplicationRecord < ::ActiveRecord::Base +class ApplicationRecord < ActiveRecord::Base self.abstract_class = true extend ActsAsRecursiveTree::ActsMacro diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 14d316b..c52dc85 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[File.join(__dir__, 'support/**/*.rb')].sort.each { |f| require f } +Dir[File.join(__dir__, 'support/**/*.rb')].each { |f| require f } # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. diff --git a/spec/support/shared_examples/builders.rb b/spec/support/shared_examples/builders.rb index c65deb7..e24bf62 100644 --- a/spec/support/shared_examples/builders.rb +++ b/spec/support/shared_examples/builders.rb @@ -15,7 +15,7 @@ let(:exclude_ids) { false } let(:proc) { nil } let(:builder) do - described_class.new(model_class, model_id, exclude_ids: exclude_ids, &proc) + described_class.new(model_class, model_id, exclude_ids:, &proc) end end diff --git a/spec/support/tree_methods.rb b/spec/support/tree_methods.rb index 3ecdb98..464cc82 100644 --- a/spec/support/tree_methods.rb +++ b/spec/support/tree_methods.rb @@ -14,8 +14,8 @@ def create_tree(max_level, current_level: 0, node: nil, create_node_info: false, max_level, current_level: current_level + 1, node: child, - create_node_info: create_node_info, - stop_at: stop_at + create_node_info:, + stop_at: ) end node