# Terraforming Rails

> A collection of tools and guides to help turn legacy Ruby on Rails code into legendary code.

- URL: https://evilmartians.com/opensource/terraforming-rails
- GitHub: https://github.com/evilmartians/terraforming-rails
- Authors: Vladimir Dementyev

---

Terraforming Rails is a collection of tools and guides to help turn legacy Ruby on Rails code into legendary code. This means it has linters, profilers, database-specific libraries, dead code elimination, configuration, analysis, automation tools, and sample tool configurations.

Based on the RailsConf 2019 talk ["Terraforming legacy Rails applications"](https://railsconf.com/program/sessions#session-832) ([slides](https://speakerdeck.com/palkan/railsconf-2019-terraforming-legacy-rails-applications), [video](https://www.youtube.com/watch?v=-NKpMn6XSjU)).

## Tools

### Unreleased scripts

These scripts have been created during the development of different Rails projects at Evil Martians.

They're not universal enough to be extracted into libraries (some depend on particular Rails version or rely on project-specific assumptions), but they could be used a starting point for building tools for your project.

- Lint/Env: RuboCop cop (restrict the usage of `ENV` and `Rails.env` in the app)
- FactoryLinter: lint factory definitions
- TimecopLinter: make sure you always travel back in time when using Timecop
- TemplatesTracker: track unused templates
- GemTracker: track potentially unused gems.

### Gems

#### Tests

- [TestProf](https://evilmartians.com/opensource/testprof): analyze and improve test suite performance

#### Security

- [bundler-audit](https://github.com/rubysec/bundler-audit): check dependencies for known CVEs
- [brakeman](https://brakemanscanner.org): detect the app code's security issues

#### Database

- [database_validations](https://github.com/toptal/database_validations): validations consistent with the DB constraints
- [database_consistency](https://github.com/djezzzl/database_consistency): check the consistency of the DB constraints and models validations
- [isolator](https://evilmartians.com/opensource/isolator): detect transactions with side-effects (_non-atomic_)

#### Dead code elimination

- [traceroute](https://github.com/amatsuda/traceroute): detect unused routes/controller actions
- [factory_trace](https://github.com/djezzzl/factory_trace): detect unused FactoryBot factories/traits

#### Configuration

- [anyway_config](https://evilmartians.com/opensource/anyway-config): transparently use multiple sources of configuration at once

#### Analysis

- [attractor](https://github.com/julianrubisch/attractor): churn/complexity analysis

### Automation Tools

- [lefthook](https://evilmartians.com/opensource/lefthook): language-agnostic git hook manager
- danger: code review automation helper
- [pronto](https://github.com/prontolabs/pronto): linters runner to run checks only for the relevant changes

## Examples

- CircleCI: example CircleCI configuration files
- [Docker for Dev](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development): example Docker for development configuration
- [Lefthook + Crystalball](https://evilmartians.com/chronicles/lefthook-crystalball-and-git-magic): Git hooks for convenient development environment

## Resources/Guides

- Fight the flaky tests
