Skip to content

Support rails 8 #1044

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'

ruby '>= 2.4.0'
ruby '>= 3.0.0'

gem 'activerecord', '>= 4.2.5', '< 6', require: false
gem 'activerecord', '>= 4.2.5', '< 9', require: false
gem 'rake', require: false

group :development do
Expand All @@ -29,7 +29,6 @@ group :development, :test do
gem 'coveralls'

gem 'overcommit'
gem 'ruby_dep', '1.5.0'

platforms :mri, :mingw do
gem 'pry', require: false
Expand Down
4 changes: 2 additions & 2 deletions annotate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Gem::Specification.new do |s|
s.name = 'annotate'
s.version = Annotate.version

s.required_ruby_version = '>= 2.4.0'
s.required_ruby_version = '>= 3.0.0'

Choose a reason for hiding this comment

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

high

Setting s.required_ruby_version to >= 3.0.0 is a significant change. While this may be necessary for future Rails versions like Rails 8, it will make new versions of annotate_models incompatible for projects using older Ruby versions (e.g., 2.5-2.7), even if those projects are on Rails versions (like Rails 5.x, 6.x) that are otherwise within the activerecord dependency range of ['>= 3.2', '< 9.0'].

For instance, a project on Rails 6.0 with Ruby 2.7 would no longer be able to update annotate_models to this version or newer without also upgrading their Ruby environment.

This effectively means dropping support for Ruby versions older than 3.0. Please consider the following:

  1. Is this breaking change intentional and its impact assessed?
  2. If so, this change should ideally be part of a major version bump for the gem (e.g., from 3.x.x to 4.x.x) and be clearly communicated in the changelog.
  3. The activerecord lower bound of >= 3.2 might also need reconsideration or clarification, as these very old ActiveRecord versions are not practically usable with Ruby 3.0.

s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.authors = ['Alex Chaffee', 'Cuong Tran', 'Marcos Piccinini', 'Turadg Aleahmad', 'Jon Frisby']
s.description = 'Annotates Rails/ActiveRecord Models, routes, fixtures, and others based on the database schema.'
Expand All @@ -23,7 +23,7 @@ Gem::Specification.new do |s|

s.specification_version = 4 if s.respond_to? :specification_version
s.add_runtime_dependency(%q<rake>, '>= 10.4', '< 14.0')
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 8.0'])
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 9.0'])

s.metadata = {
"bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/",
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3087,8 +3087,11 @@ class User < ActiveRecord::Base
end

it 'displays the error message and stacktrace with trace enabled' do
expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true }.to output(a_string_including("Unable to deannotate #{@model_dir}/user.rb: oops")).to_stderr
expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true }.to output(a_string_including("/user.rb:2:in `<class:User>'")).to_stderr
output = capture_stderr do
AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true
end
expect(output).to include("Unable to deannotate #{@model_dir}/user.rb: oops")
expect(output).to include('/user.rb:2:in')
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'logger'

Choose a reason for hiding this comment

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

medium

The logger library is imported here, but it doesn't appear to be used within this file or by the changes introduced in this pull request. If it's not utilized elsewhere in the test suite or supporting code, consider removing this line to keep dependencies minimal and avoid loading unnecessary code.

require 'active_support'

# Ruby 3 removes File.exists? in favor of File.exist?
unless File.respond_to?(:exists?)
class << File
alias exists? exist?
end
end

def capture_stderr
old, $stderr = $stderr, StringIO.new
yield
$stderr.string
ensure
$stderr = old
end
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/string/inflections'
Expand Down
Loading