diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 370eaae..c8c2f4f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: rails: [6.1, "7.0", 7.1, 7.2] env: - RAILS_VERSION: "~> ${{ matrix.rails }}.0" + RAILS_VERSION: ${{ matrix.rails }} steps: - uses: actions/checkout@v7 diff --git a/example/.gitignore b/example/.gitignore index ba66214..09edb9c 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -8,3 +8,6 @@ tmp/**/* # Not committing the schema as we shouldn't need it /db/schema.rb + +# allow using bundler binstubs but we don't want to version them +bin diff --git a/example/Gemfile b/example/Gemfile index 9ecb492..a88e712 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -1,6 +1,8 @@ source "https://rubygems.org" -gem "rails", ENV.fetch("RAILS_VERSION", "~> 7.2") +rails_version = Gem::Version.new ENV.fetch("RAILS_VERSION", "7.2") + +gem "rails", rails_version.approximate_recommendation # ~> major.minor gem "good_migrations", path: ".." @@ -10,7 +12,9 @@ gem "zeitwerk", "~> 2.6" gem "bootsnap", require: false -# activesupport needs these but older rails got it from stdlib -gem "bigdecimal" # since ruby 3.4 -gem "mutex_m" # since ruby 3.4 -gem "benchmark" # since ruby 4.0 +# activesupport 6.1 needs these but older rails got it from stdlib +if Gem::Requirement.new("~> 6.1") === rails_version + gem "bigdecimal" # since ruby 3.4 + gem "mutex_m" # since ruby 3.4 + gem "benchmark" # since ruby 4.0 +end diff --git a/example/Rakefile b/example/Rakefile index 725024f..5b35858 100644 --- a/example/Rakefile +++ b/example/Rakefile @@ -2,6 +2,10 @@ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path("../config/application", __FILE__) -require "rake" - Example::Application.load_tasks + +require "rake/clean" +CLEAN.include("db/*.sqlite3") # clear dbs between unit tests +CLOBBER.include(Bundler.default_lockfile) # clear lockfile before script/setup + +Rake::Task["clean"].enhance %w[log:clear tmp:clear] diff --git a/example/bin/setup b/example/bin/setup new file mode 100755 index 0000000..ab85f58 --- /dev/null +++ b/example/bin/setup @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby +require "fileutils" +require "bundler" + +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # Rails scaffolded, but modified for abnormal example-app purposes. + + puts "\n== Removing bundler lockfile ==\n#{Bundler.default_lockfile}" + system! "rm -f #{Bundler.default_lockfile}" + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + system! "bundle binstubs --all" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rake clean" +end diff --git a/example/config/application.rb b/example/config/application.rb index 60ee48e..6f566db 100644 --- a/example/config/application.rb +++ b/example/config/application.rb @@ -42,6 +42,6 @@ class Application < Rails::Application # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] - config.autoloader = ENV["AUTOLOADER"] == "zeitwerk" ? :zeitwerk : :classic + config.autoloader = (ENV["AUTOLOADER"] == "zeitwerk") ? :zeitwerk : :classic end end diff --git a/example/script/rails b/example/script/rails deleted file mode 100755 index 9a5a81d..0000000 --- a/example/script/rails +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -APP_PATH = File.expand_path("../../config/application", __FILE__) -require File.expand_path("../../config/boot", __FILE__) -require "rails/commands" diff --git a/example/script/setup b/example/script/setup new file mode 100755 index 0000000..d4f0333 --- /dev/null +++ b/example/script/setup @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -euo pipefail +exec "$(dirname "$0")/../bin/setup" diff --git a/script/test b/script/test index fd801fc..9c9d683 100755 --- a/script/test +++ b/script/test @@ -1,13 +1,5 @@ #!/usr/bin/env bash - set -euo pipefail -echo "---> Installing dependencies in example app" -cd example -bundle -cd .. - echo "---> Running tests" -bundle exec rake - -echo "---> Job's done!" +exec "$(dirname "$0")/../bin/rake" diff --git a/test/good_migrations_test.rb b/test/good_migrations_test.rb index 99d80b4..07bbcfd 100644 --- a/test/good_migrations_test.rb +++ b/test/good_migrations_test.rb @@ -1,6 +1,10 @@ require "test_helper" class GoodMigrationsTest < Minitest::Test + def setup + shell("bin/rake clean") + end + def test_that_it_has_a_version_number refute_nil ::GoodMigrations::VERSION end @@ -47,14 +51,8 @@ def test_that_it_has_a_version_number private def shell(command) - script = <<-SCRIPT - export BUNDLE_GEMFILE="Gemfile" - export RAILS_ENV="development" - rm -f db/*.sqlite3 - #{command} - SCRIPT Bundler.with_unbundled_env do - Open3.capture3(script, chdir: "example") + Open3.capture3(command, chdir: "example") end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index b672139..e2ed97d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,12 +8,6 @@ require "open3" require "pry" -pre_test_setup_script = <<-SCRIPT - export BUNDLE_GEMFILE="Gemfile" - export RAILS_ENV="development" - rm -f Gemfile.lock - bundle install -SCRIPT Bundler.with_unbundled_env do - Open3.capture3(pre_test_setup_script, chdir: "example") + Open3.capture3("bin/setup", chdir: "example") end