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

Add support for Rails 8.0 #572

Open
wants to merge 1 commit into
base: core
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why we need this file, especially with .0 ...

5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ sqlite = ENV['SQLITE_VERSION']
if sqlite
gem 'sqlite3', sqlite, platforms: [:ruby]
else
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
# Rails 8.0 requires sqlite3 2.x
gem 'sqlite3', ENV['RAILS']&.start_with?('~> 8') ? '~> 2.1' : '~> 1.4', platforms: [:ruby]
end

platforms :jruby do
Expand All @@ -20,7 +21,7 @@ if RUBY_ENGINE == 'rbx'
end
end

rails = ENV['RAILS'] || '~> 6.0.4'
rails = ENV['RAILS'] || '~> 6.1.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could move up the rails initialization, before sqlite and use the var instead, but I can see how its equivalent. so maybe its OK as-is


if rails == 'edge'
gem 'rails', github: 'rails/rails'
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ For Rails 4 and 5, please use version 2 of Paranoia (2.2 or greater required for
gem "paranoia", "~> 2.2"
```

For Rails 6, 7 and 8, please use version 3 of Paranoia:

``` ruby
gem "paranoia", "~> 3.0"
```

Of course you can install this from GitHub as well from one of these examples:

``` ruby
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails3"
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails4"
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails5"
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails6"
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails7"
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails8"
```

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

## Requirements

* Ruby >= 3.2.0 (required for Rails 8.0)
* Rails >= 6.1, < 9.0
* ActiveRecord >= 6.1

### Version Compatibility

| Rails Version | Paranoia Version | Ruby Version |
|--------------|------------------|--------------|
| Rails 8.0 | >= 3.0 | >= 3.2.0 |
| Rails 7.x | >= 3.0 | >= 2.7.0 |
| Rails 6.1 | >= 3.0 | >= 2.7.0 |
| Rails 5.x | 2.6.2 | >= 2.4.0 |

For Rails 5 support, use version 2.6.2.

## Callbacks

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
Expand Down
4 changes: 2 additions & 2 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'active_record' unless defined? ActiveRecord

if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] ||
ActiveRecord::VERSION::MAJOR > 5
ActiveRecord::VERSION::MAJOR >= 6
require 'paranoia/active_record_5_2'
Copy link
Collaborator

@mathieujobin mathieujobin Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this change, this looks badly named... do we need this patch for rails 6, 7 and 8 ?

end

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

# If you want to find all records, even those which are deleted
def with_deleted
if ActiveRecord::VERSION::STRING >= "4.1"
if ActiveRecord::VERSION::STRING >= "6.0"
return unscope where: paranoia_column
end
all.tap { |x| x.default_scoped = false }
Expand Down
9 changes: 5 additions & 4 deletions paranoia.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Gem::Specification.new do |s|
s.email = %w(ben@benmorgan.io john.hawthorn@gmail.com)
s.homepage = "https://github.com/rubysherpas/paranoia"
s.license = 'MIT'
s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, using much, much, much less code."
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."
s.description = <<-DSC
Paranoia is a re-implementation of acts_as_paranoid for Rails 5, 6, and 7,
Paranoia is a re-implementation of acts_as_paranoid for Rails 5, 6, 7, and 8,
using much, much, much less code. You would use either plugin / gem if you
wished that when you called destroy on an Active Record object that it
didn't actually destroy it, but just "hid" the record. Paranoia does this
Expand All @@ -22,9 +22,10 @@ Gem::Specification.new do |s|

s.required_rubygems_version = ">= 1.3.6"

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

s.add_dependency 'activerecord', '>= 6', '< 8.1'
s.add_dependency 'activerecord', '>= 6.1', '< 9'

s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "rake"
Expand Down
60 changes: 60 additions & 0 deletions test_all_rails.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -e # Exit on error

# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Rails versions to test
RAILS_VERSIONS=(
"~> 6.1.0"
"~> 7.0.0"
"~> 7.1.0"
"~> 7.2.0"
"~> 8.0.0"
)

# Function to run tests for a specific Rails version
test_rails_version() {
local version=$1
echo -e "\n${GREEN}Testing Rails ${version}...${NC}"

# Update Rails and sqlite3
RAILS="$version" bundle update rails sqlite3
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to update Rails ${version}${NC}"
return 1
fi

# Run tests
RAILS="$version" bundle exec rake test
if [ $? -ne 0 ]; then
echo -e "${RED}Tests failed for Rails ${version}${NC}"
return 1
fi

echo -e "${GREEN}Rails ${version} tests passed successfully!${NC}"
return 0
}

# Main execution
failed_versions=()

for version in "${RAILS_VERSIONS[@]}"; do
if ! test_rails_version "$version"; then
failed_versions+=("$version")
fi
done

# Summary
echo -e "\n${GREEN}Test Summary:${NC}"
if [ ${#failed_versions[@]} -eq 0 ]; then
echo -e "${GREEN}All Rails versions tested successfully!${NC}"
exit 0
else
echo -e "${RED}Tests failed for the following Rails versions:${NC}"
printf "${RED}%s${NC}\n" "${failed_versions[@]}"
exit 1
fi