diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 00000000..944880fa --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.0 diff --git a/Gemfile b/Gemfile index 66ecd287..cbcbccab 100644 --- a/Gemfile +++ b/Gemfile @@ -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 @@ -20,7 +21,7 @@ if RUBY_ENGINE == 'rbx' end end -rails = ENV['RAILS'] || '~> 6.0.4' +rails = ENV['RAILS'] || '~> 6.1.0' if rails == 'edge' gem 'rails', github: 'rails/rails' diff --git a/README.md b/README.md index 3d98b90c..fc0abe4a 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/lib/paranoia.rb b/lib/paranoia.rb index 93bf9730..2d36c05e 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -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' end @@ -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 } diff --git a/paranoia.gemspec b/paranoia.gemspec index 9baf38e6..5430a62f 100644 --- a/paranoia.gemspec +++ b/paranoia.gemspec @@ -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 @@ -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" diff --git a/test_all_rails.sh b/test_all_rails.sh new file mode 100755 index 00000000..3c1a8dbb --- /dev/null +++ b/test_all_rails.sh @@ -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