Skip to content

Commit

Permalink
Add support for Rails 7 (#460)
Browse files Browse the repository at this point in the history
* 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 <andrewwh@gmail.com>
  • Loading branch information
peterberkenbosch and andrewhampton authored Jan 11, 2022
1 parent 388ef53 commit 0272e84
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- rails_5_2
- rails_6_0
- rails_6_1
- rails_7_0
- rails_main
exclude:
- ruby: '3.0'
Expand All @@ -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
Expand Down Expand Up @@ -56,6 +60,7 @@ jobs:
- rails_5_2
- rails_6_0
- rails_6_1
- rails_7_0
- rails_main
exclude:
- ruby: '3.0'
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,4 +7,3 @@ end
appraise "rails-main" do
gem "rails", github: "rails/rails", branch: "main"
end

5 changes: 2 additions & 3 deletions awesome_nested_set.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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__)]
Expand Down
13 changes: 13 additions & 0 deletions gemfiles/rails_7_0.gemfile
Original file line number Diff line number Diff line change
@@ -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: "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_main.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

0 comments on commit 0272e84

Please sign in to comment.