From 0272e845d48728c2efda1fd3ff5ec0cd0f51e516 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Tue, 11 Jan 2022 03:48:43 +0100 Subject: [PATCH] Add support for Rails 7 (#460) * Add support for Rails 7 * Add Rails 7 to github action CI flow * Update dependency to rake ~> 12 * Fix specs and rework database loading (#1) The older version of combustion used by awesome_nested_set doesn't appear to be compatible with rails 7, and the latest version of combustion no longer has an API that lets you pass in a config. So this commit drops the dependency on combustion and just uses the rails task for database setup and teardown. Co-authored-by: Andrew Hampton --- .github/workflows/ci.yml | 12 ++++++++++++ Appraisals | 3 +-- awesome_nested_set.gemspec | 5 ++--- gemfiles/rails_7_0.gemfile | 13 +++++++++++++ gemfiles/rails_main.gemfile | 2 +- spec/spec_helper.rb | 11 +++++++---- 6 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 gemfiles/rails_7_0.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 081176d3..35691e35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,7 @@ jobs: - rails_5_2 - rails_6_0 - rails_6_1 + - rails_7_0 - rails_main exclude: - ruby: '3.0' @@ -27,6 +28,9 @@ jobs: # Rails 7 requires Ruby 2.7 or higher - ruby: '2.6' gemfile: rails_main + + - ruby: '2.6' + gemfile: rails_7_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile BUNDLE_PATH_RELATIVE_TO_CWD: true @@ -56,6 +60,7 @@ jobs: - rails_5_2 - rails_6_0 - rails_6_1 + - rails_7_0 - rails_main exclude: - ruby: '3.0' @@ -64,6 +69,9 @@ jobs: # Rails 7 requires Ruby 2.7 or higher - ruby: '2.6' gemfile: rails_main + + - ruby: '2.6' + gemfile: rails_7_0 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile BUNDLE_PATH_RELATIVE_TO_CWD: true @@ -108,12 +116,16 @@ jobs: - rails_5_2 - rails_6_0 - rails_6_1 + - rails_7_0 - rails_main exclude: - ruby: '3.0' gemfile: rails_5_2 # Rails 7 requires Ruby 2.7 or higher + - ruby: '2.6' + gemfile: rails_7_0 + - ruby: '2.6' gemfile: rails_main env: diff --git a/Appraisals b/Appraisals index dbb3bba3..bb2e63b5 100644 --- a/Appraisals +++ b/Appraisals @@ -1,4 +1,4 @@ -{ '5_2' => '5.2.0', '6_0' => '6.0.0', '6_1' => '6.1.0' }.each do |rails, version| +{ '5_2' => '5.2.0', '6_0' => '6.0.0', '6_1' => '6.1.0', '7_0' => '7.0.0' }.each do |rails, version| appraise "rails-#{rails}" do gem "rails", "~> #{version}" end @@ -7,4 +7,3 @@ end appraise "rails-main" do gem "rails", github: "rails/rails", branch: "main" end - diff --git a/awesome_nested_set.gemspec b/awesome_nested_set.gemspec index 4844863d..3de83bd6 100644 --- a/awesome_nested_set.gemspec +++ b/awesome_nested_set.gemspec @@ -18,14 +18,13 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.0.0' - s.add_runtime_dependency 'activerecord', '>= 4.0.0', '< 7.0' + s.add_runtime_dependency 'activerecord', '>= 4.0.0', '< 7.1' s.add_development_dependency 'appraisal' - s.add_development_dependency 'combustion', '>= 0.5.2', '< 0.5.5' s.add_development_dependency 'database_cleaner' s.add_development_dependency 'pry' s.add_development_dependency 'pry-nav' - s.add_development_dependency 'rake', '~> 10' + s.add_development_dependency 'rake', '~> 12' s.add_development_dependency 'rspec-rails', '~> 4.0.0' s.cert_chain = [File.expand_path('certs/parndt.pem', __dir__)] diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile new file mode 100644 index 00000000..5d1d3427 --- /dev/null +++ b/gemfiles/rails_7_0.gemfile @@ -0,0 +1,13 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "~> 7.0.0" + +platforms :ruby do + gem "sqlite3" + gem "mysql2", "< 1.0.0" + gem "pg", "< 2.0.0" +end + +gemspec path: "../" diff --git a/gemfiles/rails_main.gemfile b/gemfiles/rails_main.gemfile index 38c669ae..be0278d9 100644 --- a/gemfiles/rails_main.gemfile +++ b/gemfiles/rails_main.gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", github: "rails/rails" +gem "rails", github: "rails/rails", branch: "main" platforms :ruby do gem "sqlite3" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 99d0d7e1..6e4fdd72 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,12 +10,15 @@ require 'yaml' require 'erb' -ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result) +db_config = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result) +ActiveRecord::Base.configurations = db_config ActiveRecord::Base.establish_connection((ENV["DB"] ||= "sqlite3mem").to_sym) ActiveRecord::Migration.verbose = false -require 'combustion/database' -Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]].stringify_keys) +unless /sqlite/ === ENV['DB'] + ActiveRecord::Tasks::DatabaseTasks.create db_config[ENV['DB']] +end + load(File.join(plugin_test_dir, "db", "schema.rb")) require 'awesome_nested_set' @@ -33,7 +36,7 @@ config.use_transactional_fixtures = true config.after(:suite) do unless /sqlite/ === ENV['DB'] - Combustion::Database.drop_database(ActiveRecord::Base.configurations[ENV['DB']]) + ActiveRecord::Tasks::DatabaseTasks.drop db_config[ENV['DB']] end end end