Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Update rails to 8.0 #27

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ["3.0", "3.1"]
ruby-version: ["3.2", "3.3"]

services:
db:
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
ruby-version: "3.2"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run rubocop
run: bundle exec rubocop
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
ruby-version: "3.2"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Prepare
env:
Expand Down
9 changes: 1 addition & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gem 'actionpack'
gem 'activerecord'
gem 'railties'

gem 'pg', '< 1.3.0' # newer requires posgresql >= 9.3
gem 'pg'

gem 'active_model_serializers'
gem 'jwt'
Expand All @@ -28,9 +28,6 @@ gem 'bootsnap', require: false
# which is currently not available in production.
gem 'rdoc', '< 6.4.0'

# Ruby 3.0 uses this version of the base64 default gem
gem 'base64', '0.1.0'

group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Expand All @@ -48,10 +45,6 @@ group :development do
gem 'rubocop-rails'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'

# Loading the listen gem enables an evented file system monitor. Check
# https://github.com/guard/listen#listen-adapters if on Windows or *BSD.
# gem 'listen', '~> 3.0.4'
end

group :test do
Expand Down
55 changes: 28 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
GEM
remote: https://rubygems.org/
specs:
actionpack (7.1.5)
actionview (= 7.1.5)
activesupport (= 7.1.5)
actionpack (8.0.0)
actionview (= 8.0.0)
activesupport (= 8.0.0)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview (7.1.5)
activesupport (= 7.1.5)
useragent (~> 0.16)
actionview (8.0.0)
activesupport (= 8.0.0)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
Expand All @@ -22,25 +22,25 @@ GEM
activemodel (>= 4.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activemodel (7.1.5)
activesupport (= 7.1.5)
activerecord (7.1.5)
activemodel (= 7.1.5)
activesupport (= 7.1.5)
activemodel (8.0.0)
activesupport (= 8.0.0)
activerecord (8.0.0)
activemodel (= 8.0.0)
activesupport (= 8.0.0)
timeout (>= 0.4.0)
activesupport (7.1.5)
activesupport (8.0.0)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
airbrussh (1.5.3)
sshkit (>= 1.6.1, != 1.7.0)
ast (2.4.2)
Expand Down Expand Up @@ -105,7 +105,6 @@ GEM
ruby2_keywords (>= 0.0.5)
msgpack (1.7.5)
multi_json (1.15.0)
mutex_m (0.2.0)
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
Expand All @@ -122,7 +121,7 @@ GEM
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pg (1.2.3)
pg (1.5.9)
puma (6.4.3)
nio4r (~> 2.0)
racc (1.8.1)
Expand All @@ -147,13 +146,13 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
rails-i18n (7.0.10)
rails-i18n (8.0.1)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (7.1.5)
actionpack (= 7.1.5)
activesupport (= 7.1.5)
irb
railties (>= 8.0.0, < 9)
railties (8.0.0)
actionpack (= 8.0.0)
activesupport (= 8.0.0)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
Expand Down Expand Up @@ -198,8 +197,9 @@ GEM
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
spring (4.2.1)
sqlite3 (2.0.4)
sqlite3 (2.2.0)
mini_portile2 (~> 2.8.0)
sqlite3 (2.2.0-x86_64-linux-gnu)
sshkit (1.23.2)
base64
net-scp (>= 1.1.2)
Expand All @@ -214,7 +214,9 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
zeitwerk (2.6.18)
uri (1.0.2)
useragent (0.16.10)
zeitwerk (2.7.1)

PLATFORMS
ruby
Expand All @@ -224,15 +226,14 @@ DEPENDENCIES
actionpack
active_model_serializers
activerecord
base64 (= 0.1.0)
bootsnap
byebug
capistrano-passenger
capistrano-rails
jwt
kaminari
mocha
pg (< 1.3.0)
pg
puma
rack-cors
rails-erd
Expand Down
10 changes: 9 additions & 1 deletion app/models/access_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

class AccessCode < ApplicationRecord

include UserStampable
CODE_LENGTH = 6

attr_readonly :code

belongs_to :creator, optional: true, class_name: 'User'

validates :expires_at, presence: true

before_validation :generate_code, on: :create
before_save :set_user_stamps

scope :list, -> { order(expires_at: :desc) }
scope :expired, -> { where(expires_at: ...Time.zone.today) }
Expand All @@ -32,4 +34,10 @@ def generate_code
generate_code if AccessCode.exists?(code: code)
end

def set_user_stamps
return unless User.current

self.creator = User.current if new_record?
end

end
4 changes: 2 additions & 2 deletions app/models/archive_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ArchiveFormat < ApplicationRecord

attr_readonly :codec

enum download_permission: { public: 0, logged_in: 1, priviledged: 2, admin: 3 },
_prefix: true
enum :download_permission, { public: 0, logged_in: 1, priviledged: 2, admin: 3 },
prefix: true

belongs_to :profile

Expand Down
9 changes: 8 additions & 1 deletion app/models/broadcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

class Broadcast < ApplicationRecord

include UserStampable
include NonOverlappable

belongs_to :show
belongs_to :updater, optional: true, class_name: 'User'

has_many :audio_files, dependent: :restrict_with_error
has_many :tracks, dependent: :nullify
Expand All @@ -30,6 +30,7 @@ class Broadcast < ApplicationRecord
validates :started_at, :finished_at, uniqueness: true

before_validation :set_show_label_if_empty
before_save :set_user_stamps
after_create :assign_tracks

scope :list, -> { order('broadcasts.started_at') }
Expand Down Expand Up @@ -63,4 +64,10 @@ def assign_tracks
.update_all(broadcast_id: id)
end

def set_user_stamps
return unless User.current

self.updater = User.current
end

end
8 changes: 4 additions & 4 deletions app/models/concerns/user_stampable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module UserStampable
extend ActiveSupport::Concern

included do
belongs_to :creator, optional: true, class_name: 'User' if column_names.include?('creator_id')
belongs_to :updater, optional: true, class_name: 'User' if column_names.include?('updater_id')
belongs_to :creator, optional: true, class_name: 'User'
belongs_to :updater, optional: true, class_name: 'User'

before_save :set_user_stamps
end
Expand All @@ -16,8 +16,8 @@ module UserStampable
def set_user_stamps
return unless User.current

self.creator = User.current if new_record? && respond_to?(:creator=)
self.updater = User.current if respond_to?(:updater=)
self.creator = User.current if new_record?
self.updater = User.current
end

end
4 changes: 4 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

exec './bin/rails', 'server', *ARGV
10 changes: 10 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'rubygems'
require 'bundler/setup'

# explicit rubocop config increases performance slightly while avoiding config confusion.
ARGV.unshift('--config', File.expand_path('../.rubocop.yml', __dir__))

load Gem.bin_path('rubocop', 'rubocop')
7 changes: 6 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ class Application < Rails::Application
attr_accessor :settings

# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.1
config.load_defaults 8.0

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
#
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w[tasks capistrano])

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake time:zones:all" for a time zone names list. Default is UTC.
Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
end
9 changes: 9 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Cache assets for far-future expiry since they are all digest stamped.
config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" }

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = 'http://assets.example.com'

# Specifies the header that your server uses for sending files.
config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Assume all access to the app is happening through a SSL-terminating reverse proxy.
config.assume_ssl = true

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = ENV['RAAR_SSL'] == 'true'

Expand Down Expand Up @@ -62,6 +68,9 @@
end
end

# Prevent health checks from clogging up the logs.
config.silence_healthcheck_path = '/up'

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

Expand Down
5 changes: 4 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
config.eager_load = ENV['CI'].present?

# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
Expand Down Expand Up @@ -51,4 +51,7 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
end
Loading