After reading this file, you should have the necessary information to make changes to AnnotateRb.
AnnotateRb is a tool that annotates ActiveRecord model files with their model schema. At the time of writing, ActiveRecord has implementations for Postgres, SQLite3, MySQL, and Trilogy, although it should support other adapters. Databases and adapters can differ in their behaviors, so it's important to test run unit tests as well as integration tests with different adapters.
An example of database adapter differences: when creating a model migration, SQLite represents the id field as a :integer
and MySQL represents it as :bigint
.
/spec/dummyapp
contains a Rails app that is used in integration tests. It can be used for testing locally as well.
When running bundle install
within the context of dummyapp, specifying DATABASE_ADAPTER
is required, possible values at the time of writing are mysql2, pg, sqlite3
.
This environment variable is required when running the dummyapp.
AnnotateRb uses RSpec as a testing framework for unit tests.
AnnotateRb uses RSpec + Aruba to run integration tests.
I have found integration tests hard to write because we are testing a command line interface. As far as I'm aware, there aren't ways to easily debug it (i.e. add binding.pry
or binding.irb
statements) due to RSpec + Aruba.
If there is a better way to do this, please let me know.
Refer to git history for examples of previous commits.
When I run into errors with newly written integration tests, I run the gem in the context of the dummyapp (spec/dummyapp) using DATABASE_ADAPTER=sqlite3 bundle exec annotaterb models
with debug statements.
AnnotateRb uses StandardRb. This is open to changing in the future, but was chosen early on to spend as little time on configuring Rubocop.
If you intend to run integration tests locally, you will need to install the dependencies for dummyapp and setup the respective databases before being able to run them.
- Fork the repo
- Make necessary changes
- Run unit tests:
bundle exec rake spec:unit
- optional: Run integration tests
DATABASE_ADAPTER=sqlite3 bundle exec rake spec:integration
(setup) - Run StandardRb (linter)
bundle exec standardrb
, optionally can fix files using commandbundle exec standardrb --fix
(note: this can and will make changes to files) - Submit a pull request