Skip to content

Commit

Permalink
Specialize Rails7 Database setup on Heroku CI (#1257)
Browse files Browse the repository at this point in the history
* Test Rails 7 app against Heroku CI

Added a test for Rails 7 to exercise behavior in #1254. Update the Rails 7 example app to use the released version instead of alpha. Also update the app to be Heroku CI compat app (adds app.json):

- sharpstone/rails-jsbundling@34bd25c
- sharpstone/rails-jsbundling@a98a4e4
- sharpstone/rails-jsbundling@b4ec664
- sharpstone/rails-jsbundling@1fb48b4

Add CI tests against Rails 7

* Specialize Rails7 Database setup

In Rails 6.1 the tasks used for database setup in our test pack were deprecated. They were removed in Rails 7 https://edgeguides.rubyonrails.org/7_0_release_notes.html.

This commit moves to specialize the tasks for Rails7+ to use `db:schema:load` per deprecation instruction:

```
DEPRECATION WARNING: Using `bin/rails db:schema:load_if_ruby` is deprecated and will be removed in Rails 7.0. Configure the format using `config.active_record.schema_format = :ruby` to use `schema.rb` and run `bin/rails db:schema:load` instead. (called from <main> at /app/bin/rake:4)
```

* v236
  • Loading branch information
schneems authored Jan 4, 2022
1 parent accd4f8 commit 689ec98
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Main (unreleased)

## v236 (2022/01/04)

* Fix deprecated rake tasks for Rails 7 on Heroku CI (https://github.com/heroku/heroku-buildpack-ruby/pull/1257)

## v235 (2022/01/03)

* Bundler 2.x is now 2.2.33 (https://github.com/heroku/heroku-buildpack-ruby/pull/1248)
Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ namespace :buildpack do

changelog_md.write(contents.gsub("## Main (unreleased)", new_section))
end

version_rb = Pathname(__dir__).join("lib/language_pack/version.rb")
puts "Updating version.rb"
contents = version_rb.read.gsub(/BUILDPACK_VERSION = .*$/, %Q{BUILDPACK_VERSION = "#{deploy.next_version.to_s}"})
version_rb.write(contents)
end

desc "releases the next version of the buildpack"
Expand Down
2 changes: 1 addition & 1 deletion hatchet.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
- - "./repos/rails_versions/active_storage_non_local"
- 86dddf0127043abba1cb2890590a1d38f111edbd
- - "./repos/rails_versions/rails-jsbundling"
- 192a71e0931aa00724412521dcad4d1e1db2ec0f
- 34bd25cef7c09758b3e7763a5d4be6dc94364606
- - "./repos/rails_versions/rails3_default_ruby"
- a6b44db674c0d3538633989295e2cfd5e8e1ba0d
- - "./repos/rails_versions/rails42_default_ruby"
Expand Down
3 changes: 3 additions & 0 deletions lib/language_pack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
module LanguagePack::Test
end

# Behavior changes for the test pack work by opening existing language_pack
# classes and over-writing their behavior to extend test functionality
require "language_pack/test/ruby"
require "language_pack/test/rails2"
require "language_pack/test/rails7"
4 changes: 2 additions & 2 deletions lib/language_pack/test/rails2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#module LanguagePack::Test::Rails2
# Opens up the class of the Rails2 language pack and
# overwrites methods defined in `language_pack/test/ruby.rb`
class LanguagePack::Rails2
# sets up the profile.d script for this buildpack
def setup_profiled(ruby_layer_path: , gem_layer_path: )
Expand Down Expand Up @@ -51,7 +52,6 @@ def clear_db_test_tasks
end
end

private
def db_prepare_test_rake_tasks
schema_load = rake.task("db:schema:load_if_ruby")
structure_load = rake.task("db:structure:load_if_sql")
Expand Down
9 changes: 9 additions & 0 deletions lib/language_pack/test/rails7.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Opens up the class of the Rails7 language pack and
# overwrites methods defined in `language_pack/test/ruby.rb` or `language_pack/test/rails2.rb`
class LanguagePack::Rails7
# Rails removed the db:schema:load_if_ruby and `db:structure:load_if_sql` tasks
# they've been replaced by `db:schema:load` instead
def db_prepare_test_rake_tasks
["db:schema:load", "db:migrate"].map {|name| rake.task(name) }
end
end
7 changes: 5 additions & 2 deletions lib/language_pack/test/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#module LanguagePack::Test::Ruby
# Opens up the class of the Ruby language pack and
# overwrites methods defined in `language_pack/ruby.rb`
#
# Other "test packs" futher extend this behavior by hooking into
# methods or over writing methods defined here.
class LanguagePack::Ruby
def compile
new_app?
Expand Down Expand Up @@ -26,7 +30,6 @@ def compile
super
end

private
def db_prepare_test_rake_tasks
["db:schema:load", "db:migrate"].map {|name| rake.task(name) }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/language_pack/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module LanguagePack
class LanguagePack::Base
BUILDPACK_VERSION = "v234"
BUILDPACK_VERSION = "v236"
end
end
7 changes: 7 additions & 0 deletions spec/hatchet/rails7_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
end
end
end

it "Works on Heroku CI" do
Hatchet::Runner.new("rails-jsbundling").run_ci do |test_run|
expect(test_run.output).to match("db:schema:load")
expect(test_run.output).to match("db:migrate")
end
end
end

0 comments on commit 689ec98

Please sign in to comment.