| name | rails-verification |
| description | Verification loop for Rails projects: migrations, routes, security, performance, tests with coverage, asset pipeline, and deployment readiness checks before release or PR. Use when this capability is needed. |
Rails Verification Loop
Run before PRs, after major changes, and pre-deploy to ensure Rails application quality, security, and production readiness.
Phase 1: Environment Check
ruby --version
bundle --version
bundle outdated
rails --version
ruby -e "puts 'SECRET_KEY_BASE set' if ENV['SECRET_KEY_BASE']; puts 'DATABASE_URL set' if ENV['DATABASE_URL']"
node --version
yarn --version
If environment is misconfigured, stop and fix before proceeding.
Phase 2: Code Quality & Formatting
bundle exec rubocop -a
bundle exec rubocop --auto-gen-config
bundle exec rails_best_practices .
bundle exec reek
bundle exec rails zeitwerk:check
Common issues:
- Style violations (indentation, string quotes, trailing whitespace)
- N+1 query detection in controllers
- Long methods or classes
- Autoloading issues with class/module naming
Phase 3: Migration Verification
bundle exec rails db:migrate:status
bundle exec rails db:migrate
bundle exec rails db:rollback STEP=1
bundle exec rails db:migrate
git diff --name-only | grep db/migrate
Migration Checklist:
Zero-Downtime Migration Pattern:
add_column :users, :full_name, :string, default: ""
Phase 4: Route Verification
bundle exec rails routes > routes.txt
bundle exec rails routes:coverage
bundle exec rails routes | grep -v "rails/active_storage"
Route Security Checklist:
RESTful Route Review:
resources :posts do
resources :comments, only: [:index, :create, :destroy]
end
resources :posts do
member do
post :publish
post :unpublish
post :archive
get :preview
post :restore
end
end
Phase 5: Security Scan
bundle exec brakeman -q -z
bundle exec bundle-audit check --update
bundle exec rails credentials:show
git diff | grep -iE "password|secret|api_key|token" | grep -v "# "
grep -r "config.force_ssl = false" config/
grep -r "protect_from_forgery" app/controllers/
OWASP Rails Security Checklist:
Phase 6: Performance Checks
bundle exec rails server
bundle exec rails db:analyze
bundle exec rails db:schema:dump
Performance Checklist:
Phase 7: Asset Pipeline Verification
RAILS_ENV=production bundle exec rails assets:precompile
bundle exec rails runner "puts ActionController::Base.helpers.asset_path('application.css')"
grep -r "javascript_include_tag\|stylesheet_link_tag" app/views/ | grep -v "application"
bundle exec rails assets:clean
Asset Pipeline Checklist:
Phase 8: Environment Configuration
diff config/environments/development.rb config/environments/production.rb
bundle exec rails runner "puts Rails.env; puts Rails.configuration.action_mailer.delivery_method"
bundle exec rails runner "puts ENV.keys.grep(/^APP_/).inspect"
Environment Configuration Checklist:
Development:
Test:
Staging:
Production:
Phase 9: Tests + Coverage
COVERAGE=true bundle exec rspec
COVERAGE=true bundle exec rails test
bundle exec rspec spec/models/
bundle exec rspec spec/controllers/
bundle exec rspec spec/requests/
bundle exec rspec spec/system/
open coverage/index.html
Test Coverage Report:
- Total tests: X passed, Y failed, Z skipped
- Overall coverage: XX%
- Per-component breakdown
Coverage Targets:
| Component | Target |
|---|
| Models | 90%+ |
| Controllers | 80%+ |
| Serializers | 85%+ |
| Services/POROs | 90%+ |
| Jobs | 85%+ |
| Mailers | 80%+ |
| Overall | 80%+ |
Test Quality Checks:
Phase 10: Deployment Readiness
curl http://localhost:3000/health
bundle exec rails runner "ActiveRecord::Base.connection.execute('SELECT 1')"
bundle exec rails runner "Rails.cache.write('test', 'value'); puts Rails.cache.read('test')"
bundle exec sidekiq -C config/sidekiq.yml &
Deployment Checklist:
Phase 11: Database Verification
bundle exec rails db:schema:dump
git diff db/schema.rb
bundle exec rails db:seed
bundle exec rails runner "puts User.count; puts Post.count"
pg_dump myapp_production > backup.sql
createdb myapp_test_restore
psql myapp_test_restore < backup.sql
bundle exec rails dbconsole << EOF
SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC LIMIT 10;
EOF
Database Checklist:
Phase 12: Code Quality Audit
bundle exec rubocop --format offenses
bundle exec flog app/
bundle exec flay app/
bundle exec brakeman -A
bundle exec bundle-audit check
bundle exec license_finder
Code Quality Metrics:
Phase 13: Diff Review
git diff --stat origin/main
git diff origin/main
git diff --name-only origin/main
git diff origin/main | grep -i "todo\|fixme\|hack\|xxx"
git diff origin/main | grep "binding.pry"
git diff origin/main | grep "puts \|pp \|p "
git diff origin/main | grep -i "password.*=\|api_key.*="
Diff Review Checklist:
Output Template
RAILS VERIFICATION REPORT
=========================
Phase 1: Environment Check
✓ Ruby 3.2.2
✓ Rails 7.1.0
✓ Bundler 2.4.10
✓ Node.js 20.10.0
✓ All environment variables set
Phase 2: Code Quality
✓ RuboCop: 0 offenses
✓ Reek: No code smells
✓ Rails best practices: Clean
✓ Zeitwerk: All classes loadable
Phase 3: Migration Verification
✓ No pending migrations
✓ All migrations reversible
✓ No data loss operations
✓ Foreign keys indexed
✓ Zero-downtime compatible
Phase 4: Route Verification
✓ 247 routes defined
✓ All admin routes protected
✓ API versioning consistent
✓ RESTful compliance: 95%
⚠ 3 unused routes detected
Phase 5: Security Scan
✓ Brakeman: 0 security issues
⚠ Bundle-audit: 2 vulnerabilities (update nokogiri, loofah)
✓ No hardcoded secrets
✓ CSRF protection enabled
✓ Strong parameters enforced
✓ Force SSL enabled in production
Phase 6: Performance
✓ No N+1 queries detected (Bullet scan)
✓ All foreign keys indexed
✓ Counter caches configured
✓ Background jobs for async work
✓ Fragment caching implemented
⚠ Consider pagination for /posts (500+ records)
Phase 7: Asset Pipeline
✓ Assets precompile successfully
✓ CDN configured
✓ Gzip compression enabled
✓ Source maps generated
Phase 8: Environment Configuration
✓ Production config secure
✓ Staging mirrors production
✓ Environment variables documented
✓ Force SSL enabled
✓ Log level: info
Phase 9: Tests + Coverage
Tests: 1,247 examples, 0 failures, 12 pending
Coverage:
Overall: 87.3%
Models: 92.1%
Controllers: 84.5%
Services: 91.8%
Jobs: 88.3%
Mailers: 82.4%
Phase 10: Deployment Readiness
✓ Health check endpoint: 200 OK
✓ Database connectivity verified
✓ Redis cache reachable
✓ Sidekiq running
✓ Error tracking (Sentry) configured
✓ APM (New Relic) configured
✓ Log aggregation (Papertrail) active
Phase 11: Database
✓ Schema consistent
✓ Seeds runnable
✓ Backups configured
✓ Foreign keys enforced
✓ No orphaned records
Phase 12: Code Quality
✓ RuboCop: 0 offenses
✓ Flog: Average complexity 15.2
✓ Flay: 2.3% duplication
✓ Documentation complete
Phase 13: Diff Review
Files changed: 34
+1,247 lines, -523 lines
✓ No debug statements
✓ No hardcoded secrets
✓ Migrations included
✓ Error handling present
RECOMMENDATIONS:
1. ⚠ Update nokogiri and loofah (security vulnerabilities)
2. ⚠ Add pagination to /posts endpoint
3. ⚠ Remove 3 unused routes
OVERALL STATUS: ⚠️ FIX WARNINGS BEFORE DEPLOY
NEXT STEPS:
1. bundle update nokogiri loofah
2. Implement pagination for high-volume endpoints
3. Remove unused routes
4. Re-run verification
5. Deploy to staging for final testing
Pre-Deployment Checklist
Critical (Blockers):
High Priority:
Medium Priority:
Nice to Have:
Continuous Integration
GitHub Actions Example
name: Rails Verification
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name:
Quick Reference
| Check | Command |
|---|
| Environment | ruby --version && rails --version |
| Linting | bundle exec rubocop -a |
| Security | bundle exec brakeman -q && bundle-audit check |
| Migrations | bundle exec rails db:migrate:status |
| Routes | bundle exec rails routes |
| Tests | bundle exec rspec |
| Coverage | COVERAGE=true bundle exec rspec |
| Assets | RAILS_ENV=production bundle exec rails assets:precompile |
| Code quality | bundle exec rails_best_practices . |
| Diff stats | git diff --stat |
Common Issues & Solutions
Issue: Asset precompilation fails in production
bundle exec rails assets:precompile RAILS_ENV=production
Issue: Database migration fails in production
pg_dump production_db | psql staging_db
RAILS_ENV=staging bundle exec rails db:migrate
Issue: Tests pass locally but fail in CI
bundle exec rails db:test:prepare
Issue: N+1 queries in production
Issue: Memory bloat in background jobs
User.find_in_batches(batch_size: 100) do |batch|
batch.each { |user| process_user(user) }
end
Remember: Automated verification catches common issues but doesn't replace manual code review, staging environment testing, and production monitoring. Always have a rollback plan.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.