Skip to content

Commit 23806c4

Browse files
committed
Add support for Rails 8.0
1 parent 7b96793 commit 23806c4

File tree

6 files changed

+97
-8
lines changed

6 files changed

+97
-8
lines changed

Diff for: .ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.2.0

Diff for: Gemfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ sqlite = ENV['SQLITE_VERSION']
55
if sqlite
66
gem 'sqlite3', sqlite, platforms: [:ruby]
77
else
8-
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
8+
# Rails 8.0 requires sqlite3 2.x
9+
gem 'sqlite3', ENV['RAILS']&.start_with?('~> 8') ? '~> 2.1' : '~> 1.4', platforms: [:ruby]
910
end
1011

1112
platforms :jruby do
@@ -20,7 +21,7 @@ if RUBY_ENGINE == 'rbx'
2021
end
2122
end
2223

23-
rails = ENV['RAILS'] || '~> 6.0.4'
24+
rails = ENV['RAILS'] || '~> 6.1.0'
2425

2526
if rails == 'edge'
2627
gem 'rails', github: 'rails/rails'

Diff for: README.md

+26
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@ For Rails 4 and 5, please use version 2 of Paranoia (2.2 or greater required for
3535
gem "paranoia", "~> 2.2"
3636
```
3737

38+
For Rails 6, 7 and 8, please use version 3 of Paranoia:
39+
40+
``` ruby
41+
gem "paranoia", "~> 3.0"
42+
```
43+
3844
Of course you can install this from GitHub as well from one of these examples:
3945

4046
``` ruby
4147
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails3"
4248
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails4"
4349
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails5"
50+
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails6"
51+
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails7"
52+
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails8"
4453
```
4554

4655
Then run:
@@ -390,6 +399,23 @@ You can replace the older `acts_as_paranoid` methods as follows:
390399
The `recover` method in `acts_as_paranoid` runs `update` callbacks. Paranoia's
391400
`restore` method does not do this.
392401

402+
## Requirements
403+
404+
* Ruby >= 3.2.0 (required for Rails 8.0)
405+
* Rails >= 6.1, < 9.0
406+
* ActiveRecord >= 6.1
407+
408+
### Version Compatibility
409+
410+
| Rails Version | Paranoia Version | Ruby Version |
411+
|--------------|------------------|--------------|
412+
| Rails 8.0 | >= 3.0 | >= 3.2.0 |
413+
| Rails 7.x | >= 3.0 | >= 2.7.0 |
414+
| Rails 6.1 | >= 3.0 | >= 2.7.0 |
415+
| Rails 5.x | 2.6.2 | >= 2.4.0 |
416+
417+
For Rails 5 support, use version 2.6.2.
418+
393419
## Callbacks
394420

395421
Paranoia provides several callbacks. It triggers `destroy` callback when the record is marked as deleted and `real_destroy` when the record is completely removed from database. It also calls `restore` callback when the record is restored via paranoia

Diff for: lib/paranoia.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'active_record' unless defined? ActiveRecord
22

33
if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] ||
4-
ActiveRecord::VERSION::MAJOR > 5
4+
ActiveRecord::VERSION::MAJOR >= 6
55
require 'paranoia/active_record_5_2'
66
end
77

@@ -22,7 +22,7 @@ def paranoid? ; true ; end
2222

2323
# If you want to find all records, even those which are deleted
2424
def with_deleted
25-
if ActiveRecord::VERSION::STRING >= "4.1"
25+
if ActiveRecord::VERSION::STRING >= "6.0"
2626
return unscope where: paranoia_column
2727
end
2828
all.tap { |x| x.default_scoped = false }

Diff for: paranoia.gemspec

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Gem::Specification.new do |s|
99
1010
s.homepage = "https://github.com/rubysherpas/paranoia"
1111
s.license = 'MIT'
12-
s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, using much, much, much less code."
12+
s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, 5, 6, 7, and 8, using much, much, much less code."
1313
s.description = <<-DSC
14-
Paranoia is a re-implementation of acts_as_paranoid for Rails 5, 6, and 7,
14+
Paranoia is a re-implementation of acts_as_paranoid for Rails 5, 6, 7, and 8,
1515
using much, much, much less code. You would use either plugin / gem if you
1616
wished that when you called destroy on an Active Record object that it
1717
didn't actually destroy it, but just "hid" the record. Paranoia does this
@@ -22,9 +22,10 @@ Gem::Specification.new do |s|
2222

2323
s.required_rubygems_version = ">= 1.3.6"
2424

25-
s.required_ruby_version = '>= 2.7'
25+
s.required_ruby_version = '>= 2.7.0' # Base requirement for Rails 6.1
26+
s.required_ruby_version = '>= 3.2.0' if ENV['RAILS']&.start_with?('~> 8') # Rails 8.0 requirement
2627

27-
s.add_dependency 'activerecord', '>= 6', '< 8.1'
28+
s.add_dependency 'activerecord', '>= 6.1', '< 9'
2829

2930
s.add_development_dependency "bundler", ">= 1.0.0"
3031
s.add_development_dependency "rake"

Diff for: test_all_rails.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
set -e # Exit on error
4+
5+
# Colors for output
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
NC='\033[0m' # No Color
9+
10+
# Rails versions to test
11+
RAILS_VERSIONS=(
12+
"~> 6.1.0"
13+
"~> 7.0.0"
14+
"~> 7.1.0"
15+
"~> 7.2.0"
16+
"~> 8.0.0"
17+
)
18+
19+
# Function to run tests for a specific Rails version
20+
test_rails_version() {
21+
local version=$1
22+
echo -e "\n${GREEN}Testing Rails ${version}...${NC}"
23+
24+
# Update Rails and sqlite3
25+
RAILS="$version" bundle update rails sqlite3
26+
if [ $? -ne 0 ]; then
27+
echo -e "${RED}Failed to update Rails ${version}${NC}"
28+
return 1
29+
fi
30+
31+
# Run tests
32+
RAILS="$version" bundle exec rake test
33+
if [ $? -ne 0 ]; then
34+
echo -e "${RED}Tests failed for Rails ${version}${NC}"
35+
return 1
36+
fi
37+
38+
echo -e "${GREEN}Rails ${version} tests passed successfully!${NC}"
39+
return 0
40+
}
41+
42+
# Main execution
43+
failed_versions=()
44+
45+
for version in "${RAILS_VERSIONS[@]}"; do
46+
if ! test_rails_version "$version"; then
47+
failed_versions+=("$version")
48+
fi
49+
done
50+
51+
# Summary
52+
echo -e "\n${GREEN}Test Summary:${NC}"
53+
if [ ${#failed_versions[@]} -eq 0 ]; then
54+
echo -e "${GREEN}All Rails versions tested successfully!${NC}"
55+
exit 0
56+
else
57+
echo -e "${RED}Tests failed for the following Rails versions:${NC}"
58+
printf "${RED}%s${NC}\n" "${failed_versions[@]}"
59+
exit 1
60+
fi

0 commit comments

Comments
 (0)