Skip to content

Latest commit

 

History

History
147 lines (103 loc) · 4.51 KB

README.md

File metadata and controls

147 lines (103 loc) · 4.51 KB

RoleModel Rails

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

Precondition

The rolemodel_rails gem expects to be added to an existing Rails project. Typically those are started with:

rails new <app-name> --javascript=webpack --css=sass --database=postgresql --skip-test

The Devise generator requires your database to exist before running.

rails db:create

Installation

Add this line to your application's Gemfile:

group :development do
  gem 'rolemodel_rails', github: 'RoleModel/rolemodel_rails'
end

And then execute:

$ bundle

Usage

Run all generators (useful on a new app)

bin/rails g rolemodel:all

Or run a single generator

bin/rails g rolemodel:webpack

Or run a category subset

bin/rails g rolemodel:testing:all

You can see complete list of available generators (including those under the RoleModel namespace) by running

bin/rails g

Generators

Development

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 Rails 7 Example to test the usage of the generators.

recreate_rails7_example is simply a freshly generated Rails 7 app. To recreate it use:

bin/recreate_rails7_example

Then, cd into example_rails7 and run a rolemodel generator to see how it affects a new Rails 7 project. For example:

cd example_rails7
bin/rails g rolemodel:webpack

Testing

Generator specs should be added to the spec directory.

Setup & Teardown of the test-dummy app is handled for you, but there are 2 things that each spec needs in order to work correctly.

  1. A destination directory for the test-dummy app.
  2. To have your generator run against the test-dummy app.

e.g.

RSpec.describe Rolemodel::MyGenerator, type: :generator do
  destination File.expand_path('tmp/', File.dirname(__FILE__))

  before { run_generator_against_test_app }
end

Additional information about testing generators and the available assertions & matchers can be found at the following resources.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/RoleModel/rolemodel_rails.

License

The gem is available as open source under the terms of the MIT License.