Skip to content

Commit cd3c36a

Browse files
Support Rails 8.0 (#62)
1 parent 9593738 commit cd3c36a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1418
-13
lines changed

.circleci/config.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ version: 2.1
22
jobs:
33
lint:
44
docker:
5-
- image: cimg/ruby:3.1.5
5+
- image: cimg/ruby:3.1.6
66
working_directory: ~/safer_rails_console
77
steps:
88
- checkout
99
- restore_cache:
1010
keys:
11-
- v2-gems-ruby-3.1.5-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
12-
- v2-gems-ruby-3.1.5-
11+
- v2-gems-ruby-3.1.6-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
12+
- v2-gems-ruby-3.1.6-
1313
- run:
1414
name: Install Gems
1515
command: |
@@ -18,7 +18,7 @@ jobs:
1818
bundle clean
1919
fi
2020
- save_cache:
21-
key: v2-gems-ruby-3.1.5-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
21+
key: v2-gems-ruby-3.1.6-{{ checksum "safer_rails_console.gemspec" }}-{{ checksum "Gemfile" }}
2222
paths:
2323
- "vendor/bundle"
2424
- "gemfiles/vendor/bundle"
@@ -82,11 +82,15 @@ workflows:
8282
matrix:
8383
parameters:
8484
ruby_version:
85-
- 3.1.4
86-
- 3.2.2
87-
- 3.3.0
85+
- 3.1.6
86+
- 3.2.6
87+
- 3.3.6
8888
gemfile:
8989
- gemfiles/6.1.gemfile
9090
- gemfiles/7.0.gemfile
9191
- gemfiles/7.1.gemfile
9292
- gemfiles/7.2.gemfile
93+
- gemfiles/8.0.gemfile
94+
exclude:
95+
- ruby_version: 3.1.6
96+
gemfile: gemfiles/8.0.gemfile

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ end
1515
appraise '7.2' do
1616
gem 'rails', '~> 7.2.0'
1717
end
18+
19+
appraise '8.0' do
20+
gem 'rails', '~> 8.0.0'
21+
end

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v0.11.0
4+
- Add support for Rails 8.0. **Thanks [@olivier-thatch](https://github.com/olivier-thatch)**
5+
36
## v0.10.0
47
- Drop support for Ruby 3.0.
58
- Add support for Rails 7.2. **Thanks [@kwent](https://github.com/kwent)**

gemfiles/8.0.gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "rails", "~> 8.0.0"
6+
7+
gemspec path: "../"

lib/safer_rails_console/patches/sandbox/auto_rollback.rb

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ def self.handle_and_reraise_exception(error, message = 'PG::ReadOnlySqlTransacti
2424
raise error
2525
end
2626

27-
module PostgreSQLAdapterPatch
27+
# Patch for the PostgreSQL database adapter for Rails 8.0 and above.
28+
module PostgreSQLAdapteRailsPatch
29+
def internal_execute(...)
30+
super
31+
rescue StandardError => e
32+
# rubocop:disable Layout/LineLength
33+
SaferRailsConsole::Patches::Sandbox::AutoRollback.handle_and_reraise_exception(e, 'PG::ReadOnlySqlTransaction')
34+
# rubocop:enable Layout/LineLength
35+
end
36+
end
37+
38+
# Patch for the PostgreSQL database adapter for Rails 6.x and 7.x.
39+
module LegacyPostgreSQLAdapteRailsPatch
2840
def execute_and_clear(...)
2941
super
3042
rescue StandardError => e
@@ -35,10 +47,24 @@ def execute_and_clear(...)
3547
end
3648

3749
if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
38-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapterPatch)
50+
if SaferRailsConsole::RailsVersion.eight_or_above?
51+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapteRailsPatch)
52+
elsif SaferRailsConsole::RailsVersion.six_or_above?
53+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(LegacyPostgreSQLAdapteRailsPatch)
54+
end
55+
end
56+
57+
# Patch for the MySQL database adapter for Rails 8.0 and above.
58+
module MySQLAdapterRailsPatch
59+
def internal_execute(...)
60+
super
61+
rescue StandardError => e
62+
SaferRailsConsole::Patches::Sandbox::AutoRollback.handle_and_reraise_exception(e, 'READ ONLY transaction')
63+
end
3964
end
4065

41-
module MySQLPatch
66+
# Patch for the MySQL database adapter for Rails 6.x and 7.x.
67+
module LegacyMySQLAdapterRails67Patch
4268
def execute_and_free(...)
4369
super
4470
rescue StandardError => e
@@ -47,7 +73,11 @@ def execute_and_free(...)
4773
end
4874

4975
if defined?(::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)
50-
::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MySQLPatch)
76+
if SaferRailsConsole::RailsVersion.eight_or_above?
77+
::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MySQLAdapterRailsPatch)
78+
elsif SaferRailsConsole::RailsVersion.six_or_above?
79+
::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(LegacyMySQLAdapterRails67Patch)
80+
end
5181
end
5282
end
5383
end

lib/safer_rails_console/rails_version.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def six_or_above?
1616

1717
@six_or_above = SaferRailsConsole::RailsVersion::RAILS_VERSION >= ::Gem::Version.new('6.0.0')
1818
end
19+
20+
def eight_or_above?
21+
return @eight_or_above if defined?(@eight_or_above)
22+
23+
@eight_or_above = SaferRailsConsole::RailsVersion::RAILS_VERSION >= ::Gem::Version.new('8.0.0')
24+
end
1925
end
2026
end
2127
end

lib/safer_rails_console/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SaferRailsConsole
4-
VERSION = '0.10.0'
4+
VERSION = '0.11.0'
55
end

safer_rails_console.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ Gem::Specification.new do |spec|
4747
spec.add_development_dependency 'rspec_junit_formatter'
4848
spec.add_development_dependency 'salsify_rubocop', '~> 1.27.0'
4949

50-
spec.add_runtime_dependency 'rails', '>= 6.1', '< 7.3'
50+
spec.add_runtime_dependency 'rails', '>= 6.1', '< 8.1'
5151
end

spec/internal/rails_8_0/.dockerignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2+
3+
# Ignore git directory.
4+
/.git/
5+
/.gitignore
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all environment files.
11+
/.env*
12+
13+
# Ignore all default key files.
14+
/config/master.key
15+
/config/credentials/*.key
16+
17+
# Ignore all logfiles and tempfiles.
18+
/log/*
19+
/tmp/*
20+
21+
# Ignore storage (uploaded files in development and any SQLite databases).
22+
/storage/*
23+
24+
# Ignore assets.
25+
/node_modules/
26+
/app/assets/builds/*
27+
!/app/assets/builds/.keep
28+
/public/assets
29+
30+
# Ignore CI service files.
31+
/.github
32+
33+
# Ignore development files
34+
/.devcontainer
35+
36+
# Ignore Docker-related files
37+
/.dockerignore
38+
/Dockerfile*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
2+
3+
# Mark the database schema as having been generated.
4+
db/schema.rb linguist-generated
5+
6+
# Mark any vendored files as having been vendored.
7+
vendor/* linguist-vendored
8+
config/credentials/*.yml.enc diff=rails_credentials
9+
config/credentials.yml.enc diff=rails_credentials

spec/internal/rails_8_0/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# Temporary files generated by your text editor or operating system
4+
# belong in git's global ignore instead:
5+
# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all environment files.
11+
/.env*
12+
13+
# Ignore all logfiles and tempfiles.
14+
/log/*
15+
/tmp/*
16+
17+
# Ignore storage (uploaded files in development and any SQLite databases).
18+
/storage/*
19+
20+
/public/assets
21+
22+
# Ignore master key for decrypting credentials and more.
23+
/config/master.key

spec/internal/rails_8_0/Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# syntax=docker/dockerfile:1
2+
# check=error=true
3+
4+
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
5+
# docker build -t rails_8_0 .
6+
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name rails_8_0 rails_8_0
7+
8+
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
9+
10+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
11+
ARG RUBY_VERSION=3.3.5
12+
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
13+
14+
# Rails app lives here
15+
WORKDIR /rails
16+
17+
# Install base packages
18+
RUN apt-get update -qq && \
19+
apt-get install --no-install-recommends -y curl libjemalloc2 postgresql-client && \
20+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
21+
22+
# Set production environment
23+
ENV RAILS_ENV="production" \
24+
BUNDLE_DEPLOYMENT="1" \
25+
BUNDLE_PATH="/usr/local/bundle" \
26+
BUNDLE_WITHOUT="development"
27+
28+
# Throw-away build stage to reduce size of final image
29+
FROM base AS build
30+
31+
# Install packages needed to build gems
32+
RUN apt-get update -qq && \
33+
apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config && \
34+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
35+
36+
# Install application gems
37+
COPY Gemfile Gemfile.lock ./
38+
RUN bundle install && \
39+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
40+
41+
# Copy application code
42+
COPY . .
43+
44+
45+
46+
47+
# Final stage for app image
48+
FROM base
49+
50+
# Copy built artifacts: gems, application
51+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
52+
COPY --from=build /rails /rails
53+
54+
# Run and own only the runtime files as a non-root user for security
55+
RUN groupadd --system --gid 1000 rails && \
56+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
57+
chown -R rails:rails db log tmp
58+
USER 1000:1000
59+
60+
# Entrypoint prepares the database.
61+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
62+
63+
# Start server via Thruster by default, this can be overwritten at runtime
64+
EXPOSE 80
65+
CMD ["./bin/thrust", "./bin/rails", "server"]

spec/internal/rails_8_0/Gemfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Generated with:
4+
# rails new -JABTCM --skip-keeps --skip-active-storage --skip-system-test --skip-bootsnap --skip-hotwire -d postgresql spec/internal/rails_8_0
5+
# Then modified to match the others
6+
7+
source "https://rubygems.org"
8+
9+
gem "mysql2"
10+
gem "pg"
11+
gem "rails", "~> 8.0.0"
12+
13+
14+
gem 'safer_rails_console', path: '../../../'

spec/internal/rails_8_0/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# README
2+
3+
This README would normally document whatever steps are necessary to get the
4+
application up and running.
5+
6+
Things you may want to cover:
7+
8+
* Ruby version
9+
10+
* System dependencies
11+
12+
* Configuration
13+
14+
* Database creation
15+
16+
* Database initialization
17+
18+
* How to run the test suite
19+
20+
* Services (job queues, cache servers, search engines, etc.)
21+
22+
* Deployment instructions
23+
24+
* ...

spec/internal/rails_8_0/Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require_relative "config/application"
5+
6+
Rails.application.load_tasks
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Application styles */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ApplicationController < ActionController::Base
2+
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
3+
allow_browser versions: :modern
4+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ApplicationHelper
2+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class ApplicationJob < ActiveJob::Base
2+
# Automatically retry jobs that encountered a deadlock
3+
# retry_on ActiveRecord::Deadlocked
4+
5+
# Most jobs are safe to ignore if the underlying records are no longer available
6+
# discard_on ActiveJob::DeserializationError
7+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
primary_abstract_class
3+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class Model < ApplicationRecord
4+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title><%= content_for(:title) || "Rails 8 0" %></title>
5+
<meta name="viewport" content="width=device-width,initial-scale=1">
6+
<meta name="apple-mobile-web-app-capable" content="yes">
7+
<meta name="mobile-web-app-capable" content="yes">
8+
<%= csrf_meta_tags %>
9+
<%= csp_meta_tag %>
10+
11+
<%= yield :head %>
12+
13+
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
14+
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
15+
16+
<link rel="icon" href="/icon.png" type="image/png">
17+
<link rel="icon" href="/icon.svg" type="image/svg+xml">
18+
<link rel="apple-touch-icon" href="/icon.png">
19+
20+
<%# Includes all stylesheet files in app/assets/stylesheets %>
21+
<%= stylesheet_link_tag "application" %>
22+
</head>
23+
24+
<body>
25+
<%= yield %>
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)