Skip to content

Fix rails 8 build with 2781 and 2783 #2784

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

Merged
merged 4 commits into from
Sep 1, 2024
Merged
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
20 changes: 14 additions & 6 deletions Gemfile-rails-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ def add_net_gems_dependency
end
end

# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
if RUBY_VERSION.to_f < 3
# sqlite3 1.7.x doesn't work on all platforms for Ruby 2.x
gem 'sqlite3', '~> 1.4', '< 1.7', platforms: [:ruby]
else
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
def add_sqlite3_gem_dependency
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
if RUBY_VERSION.to_f < 3
# sqlite3 1.7.x doesn't work on all platforms for Ruby 2.x
gem 'sqlite3', '~> 1.4', '< 1.7', platforms: [:ruby]
else
gem 'sqlite3', '~> 1.4', platforms: [:ruby]
end
end

if RUBY_VERSION.to_f < 2.7
Expand All @@ -30,17 +32,22 @@ when /main/
gem "rails", :git => "https://github.com/rails/rails.git"
gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby]
gem 'selenium-webdriver', require: false

# Rails 8 requires 2.0.0
gem 'sqlite3', '~> 2.0', platforms: [:ruby]
when /stable$/
gem_list = %w[rails railties actionmailer actionpack activerecord activesupport activejob actionview]
gem 'activerecord-jdbcsqlite3-adapter', git: 'https://github.com/jruby/activerecord-jdbc-adapter', platforms: [:jruby]

gem_list.each do |rails_gem|
gem rails_gem, :git => "https://github.com/rails/rails.git", :branch => version
end
add_sqlite3_gem_dependency
when nil, false, ""
gem "rails", "~> 7.0.0"
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
gem 'selenium-webdriver', require: false
add_sqlite3_gem_dependency
else
version_number = version.split(' ').last
add_net_gems_dependency if version_number < '7.0'
Expand All @@ -55,4 +62,5 @@ else
else
gem 'selenium-webdriver', require: false
end
add_sqlite3_gem_dependency
end
4 changes: 3 additions & 1 deletion example_app_generator/generate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@

gsub_file "Gemfile", /.*rails-controller-testing.*/, "gem 'rails-controller-testing', git: 'https://github.com/rails/rails-controller-testing'"

# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`, and Ruby 2.7 only supports < 1.7
# sqlite3 is an optional, unspecified, dependency of which Rails 6.0 only supports `~> 1.4`, Ruby 2.7 only supports < 1.7 and Rails 8.0 only supports `~> 2.0`
if RUBY_VERSION.to_f < 3
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4', '< 1.7'"
elsif Rails::VERSION::STRING > '8'
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 2.0'"
else
gsub_file "Gemfile", /.*gem..sqlite3.*/, "gem 'sqlite3', '~> 1.4'"
end
Expand Down
18 changes: 18 additions & 0 deletions lib/rspec-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ class Railtie < ::Rails::Railtie
# As of Rails 5.1.0 you can register directories to work with `rake notes`
require 'rails/source_annotation_extractor'
::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")

# As of Rails 8.0.0 you can register directories to work with `rails stats`
if ::Rails::VERSION::STRING >= "8.0.0"
require 'rails/code_statistics'

dirs = Dir['./spec/**/*_spec.rb']
.map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }
.uniq
.select { |f| File.directory?(f) }

Hash[dirs.map { |d| [d.split('/').last, d] }].each do |type, dir|
name = type.singularize.capitalize

::Rails::CodeStatistics.register_directory "#{name} specs", dir
::Rails::CodeStatistics::TEST_TYPES << "#{name} specs"
end
end

generators = config.app_generators
generators.integration_tool :rspec
generators.test_framework :rspec
Expand Down
4 changes: 3 additions & 1 deletion lib/rspec/rails/tasks/rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ end

task default: :spec

task stats: "spec:statsetup"
if ::Rails::VERSION::STRING < "8.0.0"
task stats: "spec:statsetup"
end

desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(spec: "spec:prepare")
Expand Down