Executable Best Practices for Rails apps, based on RoleModel's best approaches
Attempts to solve the pain of:
- Setup of a new Rails app is harder than it needs to be
- We've tried application templates, but only useful onetime
- Our BestPractice learns don't often get ported into other projects as it isn't straightforward to do so
- There is an emerging pattern of libraries using generators (e.g. webpacker) to migrate a setup between library versions
The rolemodel_rails gem expects to be added to an existing Rails project. Typically those are started with:
rails new <app-name> --javascript=webpack --database=postgresql --skip-testThe Devise generator requires your database to exist before running.
rails db:createAdd this line to your application's Gemfile:
group :development do
gem 'rolemodel_rails', github: 'RoleModel/rolemodel_rails'
endAnd then execute:
$ bundle
Run all generators (useful on a new app)
bin/rails g rolemodel:allOr run a single generator
bin/rails g rolemodel:webpackOr run a category subset
bin/rails g rolemodel:testing:allYou can see complete list of available generators (including those under the RoleModel namespace) by running
bin/rails g- Github
- Semaphore
- Heroku
- Readme
- Webpack
- React
- Slim
- Optics
- Testing
- SimpleForm
- SoftDestroyable
- SaaS
- Mailers
- Linters
- UI Components
- Source Map
- Kaminari
- GoodJob
- Editors
- Tailored Select
- Lograge
Install the versions of Node and Ruby specified in .node-version and .ruby-version on your machine. https://asdf-vm.com/ is a great tool for managing language versions. Then run npm install -g yarn.
We use the embeded Rails apps (example_rails*) to test generators against. They reference the rolemodel_rails gem by local path,
so you can navigate into one of them and run your generator for immediate feedback while developing.
Before submitting a PR, run bin/bump_version for good Gem hygiene and to ensure everything continues to stay up-to-date.
Generator specs should be added to the spec directory.
Setup & Teardown of the test-dummy app is handled for you. All you need to do is run the provided helper method:
e.g.
RSpec.describe Rolemodel::MyGenerator, type: :generator do
before { run_generator_against_test_app }
endYou may also provide command line arguments to the helper method as an array:
e.g.
RSpec.describe Rolemodel::Testing::JasminePlaywrightGenerator, type: :generator do
before { run_generator_against_test_app(['--github-package-token=123']) }
endAdditional information about testing generators and the available assertions & matchers can be found at the following resources.
Bug reports and pull requests are welcome on GitHub at https://github.com/RoleModel/rolemodel_rails.
The gem is available as open source under the terms of the MIT License.