forked from fixin.me/fixin.me
Add multi-adapter test support: SQLite + MySQL via Gitea Actions and rake task
- .gitea/workflows/test.yml: two parallel CI jobs (SQLite and MySQL), each generates its own database.yml inline and runs the test suite - lib/tasks/test_multi_db.rake: `rails test:all_adapters` runs both adapters sequentially using DATABASE_URL to switch at runtime Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
50
lib/tasks/test_multi_db.rake
Normal file
50
lib/tasks/test_multi_db.rake
Normal file
@@ -0,0 +1,50 @@
|
||||
namespace :test do
|
||||
desc "Run Rails tests against all supported database adapters (SQLite, MySQL)"
|
||||
task :all_adapters do
|
||||
# DATABASE_URL overrides the adapter from database.yml at runtime.
|
||||
# MySQL requires the mysql2 gem: bundle install --with mysql
|
||||
adapters = {
|
||||
"SQLite" => {
|
||||
"DATABASE_URL" => "sqlite3:db/test.sqlite3"
|
||||
},
|
||||
"MySQL" => {
|
||||
"DATABASE_URL" => format(
|
||||
"mysql2://%s:%s@%s/%s",
|
||||
ENV.fetch("DATABASE_USERNAME", "root"),
|
||||
ENV.fetch("DATABASE_PASSWORD", ""),
|
||||
ENV.fetch("DATABASE_HOST", "127.0.0.1"),
|
||||
ENV.fetch("DATABASE_NAME", "fixin_test")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
failed = []
|
||||
|
||||
adapters.each do |name, extra_env|
|
||||
puts "\n#{"=" * 60}"
|
||||
puts " Running tests with #{name}"
|
||||
puts "=" * 60
|
||||
|
||||
env = ENV.to_h.merge("RAILS_ENV" => "test").merge(extra_env)
|
||||
|
||||
# Reset test database; db:drop may fail on first run — that's fine
|
||||
system(env, "bin/rails db:drop")
|
||||
unless system(env, "bin/rails db:create db:schema:load")
|
||||
failed << "#{name} (database setup)"
|
||||
next
|
||||
end
|
||||
|
||||
failed << name unless system(env, "bin/rails test")
|
||||
end
|
||||
|
||||
puts "\n#{"=" * 60}"
|
||||
if failed.any?
|
||||
puts " FAILED: #{failed.join(", ")}"
|
||||
puts "=" * 60
|
||||
exit 1
|
||||
else
|
||||
puts " All adapters passed!"
|
||||
puts "=" * 60
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user