Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions example/Gemfile
Original file line number Diff line number Diff line change
@@ -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: ".."

Expand All @@ -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
8 changes: 6 additions & 2 deletions example/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
24 changes: 24 additions & 0 deletions example/bin/setup
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion example/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions example/script/rails

This file was deleted.

3 changes: 3 additions & 0 deletions example/script/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
exec "$(dirname "$0")/../bin/setup"
10 changes: 1 addition & 9 deletions script/test
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 5 additions & 7 deletions test/good_migrations_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
8 changes: 1 addition & 7 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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