Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Jan 9, 2024
1 parent 2940846 commit fd44929
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 136 deletions.
52 changes: 7 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,9 @@ name: CI
on:
pull_request:
push:
branches: [ main ]
branches: [main]

jobs:
scan_ruby:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Scan for security vulnerabilities in Ruby dependencies
run: bin/brakeman

scan_js:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Scan for security vulnerabilities in JavaScript dependencies
run: bin/importmap audit

lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -51,7 +19,9 @@ jobs:
bundler-cache: true

- name: Lint code for consistent style
run: bin/rubocop -f github
run: |
gem install error_highlight -v 0.5.1
bin/rubocop -f github
test:
runs-on: ubuntu-latest
Expand All @@ -66,16 +36,7 @@ jobs:
- 5432:5432
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3

# redis:
# image: redis
# ports:
# - 6379:6379
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libvips postgresql-client libpq-dev

- name: Checkout code
uses: actions/checkout@v4

Expand All @@ -89,8 +50,9 @@ jobs:
env:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:postgres@localhost:5432
# REDIS_URL: redis://localhost:6379/0
run: bin/rails db:setup test test:system
run: |
gem install error_highlight -v 0.5.1
bin/rails db:setup test test:system
- name: Keep screenshots from failed system tests
uses: actions/upload-artifact@v4
Expand Down
28 changes: 14 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ gem "bootsnap", require: false
gem "image_processing", "~> 1.2"
gem "aws-sdk-s3", require: false

gem 'pagy'
gem "pagy"

# Authentication
gem 'devise', github: 'heartcombo/devise'
gem 'omniauth'
gem 'omniauth-rails_csrf_protection'
gem 'omniauth-google-oauth2'
gem 'omniauth-github'
gem "devise", github: "heartcombo/devise"
gem "omniauth"
gem "omniauth-rails_csrf_protection"
gem "omniauth-google-oauth2"
gem "omniauth-github"

# Background jobs
gem 'good_job'
gem "good_job"

# Data
gem 'faraday'
gem 'geocoder'
gem 'timezone'
gem 'geo_names'
gem "faraday"
gem "geocoder"
gem "timezone"
gem "geo_names"


group :development, :test do
Expand All @@ -76,9 +76,9 @@ group :development, :test do
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false

gem 'dotenv-rails'
gem "dotenv-rails"

gem 'letter_opener'
gem "letter_opener"

gem "hotwire-livereload"
end
Expand All @@ -94,7 +94,7 @@ group :development do
# gem "spring"

# Highlight the fine-grained location where an error occurred [https://github.com/ruby/error_highlight]
gem "error_highlight", ">= 0.4.0", platforms: [:ruby]
gem "error_highlight", ">= 0.4.0", platforms: [ :ruby ]
end

group :test do
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/api/exchanges_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
class Api::ExchangesController < ApiController

def index
exchanges = Exchange.order(:name)
@pagy, @exchanges = pagy(exchanges, items: 2)
@pagy_metadata = pagy_metadata(@pagy)

api_user.charge_credits(1, nil, 'Exchange index')
api_user.charge_credits(1, nil, "Exchange index")
end

def show
@exchange = Exchange.find_by('lower(acronym) = ? OR lower(mic_code) = ?', params[:id].downcase, params[:id].downcase)
@exchange = Exchange.find_by("lower(acronym) = ? OR lower(mic_code) = ?", params[:id].downcase, params[:id].downcase)

api_user.charge_credits(1, @exchange)

raise ActiveRecord::RecordNotFound if @exchange.nil?
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def set_default_response_format
end

def record_not_found
render json: { error: 'Record not found' }, status: :not_found
render json: { error: "Record not found" }, status: :not_found
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/concerns/ApiAuthentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def authenticate_token
end

def unauthenticated
render json: { error: 'Invalid API key' }, status: :unauthorized
render json: { error: "Invalid API key" }, status: :unauthorized
end
end
end
6 changes: 3 additions & 3 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class PagesController < ApplicationController
before_action :authenticate_user!, only: [:dashboard]
before_action :authenticate_user!, only: [ :dashboard ]

def index
redirect_to dashboard_path# if user_signed_in?
end

def dashboard
end
end
9 changes: 4 additions & 5 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# frozen_string_literal: true

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

def google_oauth2
@user = User.from_omniauth(request.env["omniauth.auth"], cookies[:referral])

if @user.persisted?
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
set_flash_message(:notice, :success, kind: "Google") if is_navigational_format?

cookies.signed[:user] = { value: @user.id, expires: 1.year.from_now, httponly: true }
else
session["devise.google_data"] = request.env["omniauth.auth"].except('extra')
session["devise.google_data"] = request.env["omniauth.auth"].except("extra")
redirect_to new_user_session_url
end
end

def github
@user = User.from_omniauth(request.env["omniauth.auth"], cookies[:referral])
sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
set_flash_message(:notice, :success, kind: "GitHub") if is_navigational_format?
cookies.signed[:user] = { value: @user.id, expires: 1.year.from_now, httponly: true }
end

def failure
redirect_to root_path
end

# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]

Expand Down
12 changes: 6 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ApplicationHelper
COLOR_ARRAY = ['orange', 'amber', 'yellow', 'lime', 'teal', 'cyan', 'sky', 'violet', 'purple', 'fuchsia', 'pink', 'rose', 'coral', 'pumpkin', 'orange', 'beach', 'azure', 'blue', 'indigo', 'cerise'].freeze
COLOR_ARRAY = [ "orange", "amber", "yellow", "lime", "teal", "cyan", "sky", "violet", "purple", "fuchsia", "pink", "rose", "coral", "pumpkin", "orange", "beach", "azure", "blue", "indigo", "cerise" ].freeze

def title(page_title)
content_for(:title) { page_title }
end
Expand All @@ -26,10 +26,10 @@ def subheading(subheading)
end

def navigation_link(path, text, icon)
css_class = current_page?(path) ? 'flex gap-x-2 items-center px-3 py-3 text-base font-medium text-woodsmoke-900 rounded-md hover:bg-woodsmoke-200 bg-woodsmoke-100 group'
: 'flex gap-x-2 items-center px-3 py-3 text-base font-medium text-woodsmoke-400 rounded-md hover:bg-woodsmoke-200 group'
icon_color = current_page?(path) ? 'text-caribbean-green-500' : 'text-woodsmoke-400'
css_class = current_page?(path) ? "flex gap-x-2 items-center px-3 py-3 text-base font-medium text-woodsmoke-900 rounded-md hover:bg-woodsmoke-200 bg-woodsmoke-100 group"
: "flex gap-x-2 items-center px-3 py-3 text-base font-medium text-woodsmoke-400 rounded-md hover:bg-woodsmoke-200 group"
icon_color = current_page?(path) ? "text-caribbean-green-500" : "text-woodsmoke-400"

link_to path, class: css_class do
concat(content_tag(:i, nil, class: "text-lg #{icon_color} fa-kit #{icon}"))
concat(text)
Expand Down
5 changes: 2 additions & 3 deletions app/models/exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Exchange < ApplicationRecord
has_many :operating_hours
has_many :holidays
has_many :transactions, as: :transactable, dependent: :destroy
belongs_to :parent, class_name: 'Exchange', foreign_key: 'operating_mic_code', primary_key: 'mic_code', optional: true
has_many :children, class_name: 'Exchange', foreign_key: 'operating_mic_code', primary_key: 'mic_code'

belongs_to :parent, class_name: "Exchange", foreign_key: "operating_mic_code", primary_key: "mic_code", optional: true
has_many :children, class_name: "Exchange", foreign_key: "operating_mic_code", primary_key: "mic_code"
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class User < ApplicationRecord
after_create :add_starting_credits

def self.from_omniauth(auth, referral = nil)
find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0, 20]
user.name = auth.info.name # assuming the user model has a name
Expand Down
4 changes: 2 additions & 2 deletions app/views/api/exchanges/_exchange.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ json.currency exchange.currency
json.links exchange.links

if params[:related]
if exchange.kind == 'segment'
if exchange.kind == "segment"
json.operating_exchange do
json.id exchange.parent.id
json.name exchange.parent.name
Expand All @@ -25,7 +25,7 @@ if params[:related]
end
end

if exchange.kind == 'operating'
if exchange.kind == "operating"
json.segment_exchanges do
json.array! exchange.children do |segment|
json.id segment.id
Expand Down
4 changes: 2 additions & 2 deletions app/views/api/exchanges/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
json.data do
json.partial! 'exchange', collection: @exchanges, as: :exchange
json.partial! "exchange", collection: @exchanges, as: :exchange
end
json.paging do
json.prev @pagy_metadata[:prev_url]
Expand All @@ -12,4 +12,4 @@ end
json.meta do
json.credits_used 1
json.credits_remaining @api_key.user.balance
end
end
4 changes: 2 additions & 2 deletions app/views/api/exchanges/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
json.data do
json.partial! 'exchange', locals: {exchange: @exchange}
json.partial! "exchange", locals: { exchange: @exchange }
end
json.meta do
json.credits_used 1
json.credits_remaining @api_key.user.balance
end
end
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
config.generators.apply_rubocop_autocorrect_after_generate!

# Set the default URL for Action Mailer
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

# Set host for accessing via ngrok
config.hosts << "sabotage.ngrok.dev"
Expand Down
18 changes: 9 additions & 9 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = '[email protected]'
config.mailer_sender = "[email protected]"

# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
Expand All @@ -36,7 +36,7 @@
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record'
require "devise/orm/active_record"

# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
Expand All @@ -58,12 +58,12 @@
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [:email]
config.case_insensitive_keys = [ :email ]

# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [:email]
config.strip_whitespace_keys = [ :email ]

# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
Expand Down Expand Up @@ -97,7 +97,7 @@
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing skip: :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]
config.skip_session_storage = [ :http_auth ]

# By default, Devise cleans up the CSRF token on authentication to
# avoid CSRF token fixation attacks. This means that, when using AJAX
Expand Down Expand Up @@ -273,14 +273,14 @@
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'

config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
{
name: 'google_oauth2',
name: "google_oauth2",
strategy_class: OmniAuth::Strategies::GoogleOauth2,
access_type: 'offline'
access_type: "offline"
}

config.omniauth :github, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'], scope: 'user:email'
config.omniauth :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email"

# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/generators.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Rails.application.config.generators do |g|
g.orm :active_record, primary_key_type: :uuid
end
end
Loading

0 comments on commit fd44929

Please sign in to comment.