View on GitHub

Povio Engineering Guidelines

These are guidelines for the technologies we are using.

Ruby on Rails Code Guideline

Index

Language & Framework Versions

When creating a new project:

Use the latest patched version, as they contain various fixes and security patches. Same applies to the gems. Use bundler-audit to check if there are any security updates available to the gems you are using.

Getting started

Create all new Rails projects with postgresql database and skip coffeescript

rails new project_name -d postgresql --skip-coffee --skip-turbolinks --skip-test

Add dotenv-rails for reading env values and rspec-rails for use of RSpec test framework. Also add factory_bot and faker. Do not use paperclip, its deprecated, use ActiveStorage instead.

Git ignore .env.* files. Create an empty .env.development for the development environment and .env for general use. Describe in ReadMe which envs are used and why.

Project README template

Example of a project readme template

# Project name

## General
This is the project template for the project that does this and that.

## Requirements
1. Ruby x.x.x
2. Rails x.x.x
3. Postgresql DB
4. ...
<br>

## Environmental variables
Describe what env variables are needed and why

## Logic
Any specific business logic that needs to be described.

## Tests
Testing framework is RSpec. Run tests by `bundle exec rspec` or just `rspec`

Gems

Comments

Style Guidelines

While our guidelines describes the basics, do read the full community driven style guidelines for any specific: https://github.com/rubocop-hq/rails-style-guide

Rubocop

Use Rubocop in Rails projects. The circle ci config from CircleCI chapter also assumes that you have rubocop config file read. Default Rubocop complains on newer Rails. Use this starter template and place it in root dir (.rubocop.yml, the rubocop command will pick it up) to get started right away.

AllCops:
  Exclude:
    - 'spec/**/*.rb'
    - 'lib/tasks/**/*.rake'
    - 'config/**/*.rb'
    - 'bin/**/*'
    - 'Gemfile'
    - 'Gemfile.lock'
    - 'app/admin/**/*.rb'
    - 'config.ru'
    - 'db/*.rb'
    - 'app/helpers/*.rb'
    - 'app/mailers/*.rb'
    - 'Rakefile'

Style/FrozenStringLiteralComment:
  Enabled: false

Style/Documentation:
  Enabled: false

MVC

Controllers

Models

Views/Rendering

Tests

CircleCI

Mailer

Background workers

Time

# bad
Time.parse('2015-03-02 19:05:37') # => Will assume time string given is in the system's time zone.

# good
Time.zone.parse('2015-03-02 19:05:37') # => Mon, 02 Mar 2015 19:05:37 EET +02:00

# bad
Time.now # => Returns system time and ignores your configured time zone.

# good
Time.zone.now # => Fri, 12 Mar 2014 22:04:47 EET +02:00
Time.current # Same thing but shorter.

Monitoring

Deployment

Docker