Skip to content

LunarLogic/smog_alert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smog alert

CircleCI

Requirements

  • Ruby 2.6.5
  • Node.js

Ensure you use NVM (Node Version Manager) and only then install yarn via brew.

brew install yarn
  • Install and run PostgreSQL
brew update
brew install postgresql
brew services start postgresql
  • Install and run Redis
brew update
brew install redis
brew services start redis
  • Install ImageMagic
brew install imagemagick

Development setup

bundle install
yarn install

# setup database
rake db:setup

bundle exec rails s

# In separate terminal window run:
bin/webpack-dev-server

# In separate terminal window run:
bundle exec sidekiq

# To run migrations in database:
rails db:migrate
RAILS_ENV=test rails db:migrate
  • Run seeds to setup sample records in database (email: admin@example.com, password: 123456)
rails db:seed
  • You can see background jobs in Sidekiq web view by visiting http://localhost:3000/sidekiq You must be signed in as admin user.

  • To check Rails routes

rails routes
  • To use Guard run
guard

in command line. Then when you save a file guard will automatically run tests for it

Editor config

  • Visual Studio Code
  • Install Prettier - Code formatter
  • Go to Code > Peferences > Settings > Text Editor > Formatting Turn on Format On Save checkbox From now on every change in code base will be automatically formatted by Prettier.

Deployment

  • To deploy from master branch use:

cap staging deploy

  • To specify a branch for deployment use:

BRANCH=example_branch cap staging deploy

  • Run DB seeds on container:

cap staging deploy:seed

Tips

  • Edit credentials in VIM by running:

EDITOR=vim rails credentials:edit

  • Edit credentials in VSCode by running:

EDITOR='code --wait' rails credentials:edit

or

EDITOR='code --wait' rails credentials:edit -e staging

  • To use RuboCop Linter run:

bundle exec rubocop

  • How to run rails console inside of staging container:
ssh smogalert@staging.smogalert.lunarlogic.io

# go to rails project directory
smogalert@staging:~$ cd application/current

# open rails console
RAILS_ENV=staging /usr/local/rbenv/bin/rbenv exec bundle exec rails console

Tests

  • Run the test suite: bundle exec rspec

  • Run tests in Chrome browser in development: CHROME=true rspec spec/features/homepage_spec.rb

API docs

React application uses API exposed by Rails.

We use Swagger Blocks to manage API docs.

It generates JSON API endpoint http://localhost:3000/apidocs that is translated to web page thanks to http://petstore.swagger.io See below examples.

How to preview documentation via staging

http://petstore.swagger.io/?url=https://staging.smogalert.lunarlogic.io/apidocs

How to preview documentation in development

http://petstore.swagger.io/?url=http://localhost:3000/apidocs