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

0 commit comments

Comments
 (0)