Skip to content

Commit

Permalink
NEW: Update code to rails 8 standards
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmcal committed Nov 11, 2024
1 parent 0b33158 commit 5346286
Show file tree
Hide file tree
Showing 47 changed files with 856 additions and 808 deletions.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ updates:
- package-ecosystem: "bundler"
directory: "/"
open-pull-requests-limit: 50
commit-message:
prefix: "OPT"
schedule:
interval: "weekly"
time: "08:00"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
name: Rubocop
image: "gmmcal/ynab:test-${{ github.event.number }}-${{ github.run_number }}"
command: bundle exec rubocop --config .rubocop.yml .
command: bin/rubocop
needs: build

reek:
Expand All @@ -62,7 +62,7 @@ jobs:
with:
name: Brakeman
image: "gmmcal/ynab:test-${{ github.event.number }}-${{ github.run_number }}"
command: bundle exec brakeman
command: bin/brakeman
needs: build

bundler-audit:
Expand Down
51 changes: 7 additions & 44 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
require:
- rubocop-capybara
- rubocop-rails

AllCops:
TargetRubyVersion: 3.2
DisplayCopNames: true
NewCops: enable
Exclude:
- "vendor/**/*"

Rails:
Enabled: true

Style/Documentation:
Enabled: false

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma

# rails default files things
Layout/LineLength:
Exclude:
- bin/bundle

Metrics/BlockLength:
Exclude:
- config/environments/development.rb

Metrics/CyclomaticComplexity:
Exclude:
- bin/bundle

Metrics/MethodLength:
Exclude:
- bin/bundle

Metrics/PerceivedComplexity:
Exclude:
- bin/bundle

Rails/SkipsModelValidations:
Exclude:
- db/migrate/20240401075141_add_service_name_to_active_storage_blobs.active_storage.rb
# Omakase Ruby styling for Rails
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
# Overwrite or add rules to create your own house style
#
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
# Layout/SpaceInsideArrayLiteralBrackets:
# Enabled: false
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
ruby-3.3.6
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
ARG RUBY_VERSION=3.3.6
FROM ruby:$RUBY_VERSION-slim AS base

# Rails app lives here
Expand All @@ -24,7 +24,7 @@ RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
apt-get install --no-install-recommends -y build-essential libpq-dev curl

# Install application gems
COPY Gemfile Gemfile.lock ./
COPY Gemfile Gemfile.lock .ruby-version ./
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
bundle config set app_config .bundle && \
bundle config set path /srv/vendor && \
Expand Down
51 changes: 26 additions & 25 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '~> 3.2.2'
ruby file: ".ruby-version"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 8.0.0'
gem "rails", "~> 8.0.0"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'sprockets-rails'
gem "sprockets-rails"

# Use postgresql as the database for Active Record
gem 'pg', '~> 1.5'
gem "pg"

# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '~> 6.4'
gem "puma"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem 'importmap-rails'
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem 'turbo-rails'
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem 'stimulus-rails'
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 5.3'
gem "redis"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"
Expand All @@ -39,10 +39,13 @@ gem 'redis', '~> 5.3'
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false
gem "bootsnap", require: false

# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
gem "thruster", require: false

# Use Sass to process CSS
# gem "sassc-rails"
Expand All @@ -51,23 +54,21 @@ gem 'bootsnap', require: false
# gem "image_processing", "~> 1.2"

# Retrieve data from YNAB API
gem 'ynab'
gem "ynab"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem "bundler-audit", require: false
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
gem "brakeman", require: false
gem "rubocop-rails-omakase", require: false
gem "reek"
end

group :development do
gem 'brakeman'
gem 'bundler-audit'
gem 'reek'
gem 'rubocop'
gem 'rubocop-capybara'
gem 'rubocop-rails'

# Use console on exceptions pages [https://github.com/rails/web-console]
gem 'web-console'
gem "web-console"

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
Expand All @@ -78,6 +79,6 @@ end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem 'capybara'
gem 'selenium-webdriver'
gem "capybara"
gem "selenium-webdriver"
end
56 changes: 43 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ GEM
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.5)
json (2.8.1)
language_server-protocol (3.17.0.3)
logger (1.6.1)
loofah (2.23.1)
Expand Down Expand Up @@ -178,8 +178,14 @@ GEM
nio4r (2.7.4)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
parallel (1.26.3)
Expand Down Expand Up @@ -256,15 +262,24 @@ GEM
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.33.1)
rubocop-ast (1.34.1)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-minitest (0.36.0)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.27.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails-omakase (1.0.0)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
securerandom (0.3.1)
Expand All @@ -285,6 +300,11 @@ GEM
railties (>= 6.0.0)
stringio (3.1.2)
thor (1.3.2)
thruster (0.1.8)
thruster (0.1.8-aarch64-linux)
thruster (0.1.8-arm64-darwin)
thruster (0.1.8-x86_64-darwin)
thruster (0.1.8-x86_64-linux)
timeout (0.4.2)
turbo-rails (2.0.11)
actionpack (>= 6.0.0)
Expand Down Expand Up @@ -313,8 +333,19 @@ GEM

PLATFORMS
aarch64-linux
arm64-darwin-23
aarch64-linux-gnu
aarch64-linux-musl
arm-linux
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86-linux
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
bootsnap
Expand All @@ -324,24 +355,23 @@ DEPENDENCIES
debug
importmap-rails
jbuilder
pg (~> 1.5)
puma (~> 6.4)
pg
puma
rails (~> 8.0.0)
redis (~> 5.3)
redis
reek
rubocop
rubocop-capybara
rubocop-rails
rubocop-rails-omakase
selenium-webdriver
sprockets-rails
stimulus-rails
thruster
turbo-rails
tzinfo-data
web-console
ynab

RUBY VERSION
ruby 3.2.2p53
ruby 3.3.6p108

BUNDLED WITH
2.4.10
2.5.23
4 changes: 2 additions & 2 deletions app/controllers/auths_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def create
redirect_to root_path
else
session[:authenticated] = nil
redirect_to new_auth_path, flash: { danger: 'Invalid password' }
redirect_to new_auth_path, flash: { danger: "Invalid password" }
end
end

private

def password
ENV.fetch('APPLICATION_PASSWORD', 'password')
ENV.fetch("APPLICATION_PASSWORD", "password")
end
end
16 changes: 8 additions & 8 deletions app/helpers/reports_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ def values(reports)
{
name:,
data: extract_data(value),
marker: { symbol: 'circle' },
marker: { symbol: "circle" }
}
end
end

def category_values(reports)
[{
name: 'Activity',
data: extract_data(reports),
[ {
name: "Activity",
data: extract_data(reports)
}, {
name: 'Budgeted',
name: "Budgeted",
data: extract_data(reports, :budgeted),
type: :spline,
}]
type: :spline
} ]
end

def extract_data(values, field = :activity)
values.group_by(&:date).map do |key, value|
[key.to_s, total(value, field)]
[ key.to_s, total(value, field) ]
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/lib/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def initialize(token)

def process
ActiveRecord::Base.transaction { process_months }
Rails.logger.info { 'Data successfully imported' }
Rails.logger.info { "Data successfully imported" }
end

private

def cleanup
Rails.logger.info { 'Cleaning old reports' }
Rails.logger.info { "Cleaning old reports" }
Report.delete_all
end

Expand Down Expand Up @@ -54,7 +54,7 @@ def api
end

def budget
budgets.select { |budget| budget.name == 'Personal' }.first
budgets.select { |budget| budget.name == "Personal" }.first
end

def budgets
Expand Down
Loading

0 comments on commit 5346286

Please sign in to comment.