From 678c5b2b57d3b06b9432307f00283ecc6c85ad4d Mon Sep 17 00:00:00 2001 From: Satoshi Nabetani Date: Mon, 26 Jun 2023 19:35:37 +0900 Subject: [PATCH] Ruby 3 and 3.1 (#1034) * The File.exists? method was removed in Ruby 3.0 We should use `File.exist?` instead. * Add Ruby 3.0 to CI matrix * Updated gem version to be compatible with Ruby 3.0 * Removed settings for older Ruby versions * Added Active Storage configuration for testing * Replaced deprecated 'update_attributes' method with 'update' * Add Ruby 3.1 to CI matrix * Update Rails minimum version dependency to 5 --------- Co-authored-by: Nicholas Jakobsen --- .github/workflows/ci.yml | 2 + sunspot_rails/Appraisals | 55 ++++--------------- sunspot_rails/spec/model_lifecycle_spec.rb | 2 +- sunspot_rails/spec/rails_app/config/boot.rb | 2 +- .../spec/rails_app/config/storage.yml | 3 + sunspot_rails/sunspot_rails.gemspec | 10 +--- sunspot_solr/lib/sunspot/solr/server.rb | 4 +- 7 files changed, 21 insertions(+), 57 deletions(-) create mode 100644 sunspot_rails/spec/rails_app/config/storage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9374c5cbf..9bc26059d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,8 @@ jobs: - '2.5' - '2.6' - '2.7' + - '3.0' + - '3.1' # - 'head' gem: ['sunspot', 'sunspot_rails', 'sunspot_solr'] update-format: ['xml', 'json'] diff --git a/sunspot_rails/Appraisals b/sunspot_rails/Appraisals index 75fa77807..1abad83df 100644 --- a/sunspot_rails/Appraisals +++ b/sunspot_rails/Appraisals @@ -1,64 +1,31 @@ ruby_version = Gem::Version.new(RUBY_VERSION) -if ruby_version < Gem::Version.new('2.2.0') - ['3.0.0', '3.1.0'].each do |rails_version| - appraise "rails-#{rails_version}" do - gem 'bundler', '>= 1.3.0', '< 2.0' - gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME']) - gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME']) - gem 'rails', "~> #{rails_version}" - gem 'progress_bar', '~> 1.0.5', require: false - gem 'rspec', '~> 3.4.0' - gem 'rspec-rails', '~> 3.4.0' - end - end -end - -if ruby_version < Gem::Version.new('2.4.0') - appraise 'rails-3.2.0' do - gem 'bundler', '>= 1.3.0', '< 2.0' - gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME']) - gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME']) - gem 'rails', '~> 3.2.0' - gem 'progress_bar', '~> 1.0.5', require: false - gem 'test-unit', '~> 3.2.0' - gem 'rspec', '~> 3.4.0' - gem 'rspec-rails', '~> 3.4.0' - end - - ['4.0.0', '4.1.0'].each do |rails_version| +if ruby_version < Gem::Version.new('3.0.0') + ['5.0.0', '5.1.0', '5.2.0'].each do |rails_version| appraise "rails-#{rails_version}" do - gem 'bundler', '>= 1.3.0', '< 2.0' gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME']) gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME']) gem 'rails', "~> #{rails_version}" + gem 'sprockets', '~> 3.0' gem 'progress_bar', '~> 1.0.5', require: false - gem 'rspec', '~> 3.4.0' - gem 'rspec-rails', '~> 3.4.0' + gem 'sqlite3', '~> 1.3.0' + gem 'rspec', '~> 3.7' + gem 'rspec-rails', '~> 3.7' end end end -if ruby_version < Gem::Version.new('2.5.0') - appraise 'rails-4.2.0' do - gem 'bundler', '>= 1.3.0', '< 2.0' - gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME']) - gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME']) - gem 'rails', '~> 4.2.0' - gem 'progress_bar', '~> 1.0.5', require: false - gem 'rspec', '~> 3.4.0' - gem 'rspec-rails', '~> 3.4.0' - end -end - -if ruby_version >= Gem::Version.new('2.2.0') - ['5.0.0', '5.1.0', '5.2.0'].each do |rails_version| +if Gem::Version.new('3.0.0') <= ruby_version && ruby_version < Gem::Version.new('3.3.0') + ['6.1.0', '7.0.0'].each do |rails_version| appraise "rails-#{rails_version}" do gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME']) gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME']) gem 'rails', "~> #{rails_version}" gem 'sprockets', '~> 3.0' gem 'progress_bar', '~> 1.0.5', require: false + gem 'sqlite3', '~> 1.4.0' + gem 'rspec', '~> 3' + gem 'rspec-rails', '~> 6' end end end diff --git a/sunspot_rails/spec/model_lifecycle_spec.rb b/sunspot_rails/spec/model_lifecycle_spec.rb index bfbc7467c..347fb91af 100644 --- a/sunspot_rails/spec/model_lifecycle_spec.rb +++ b/sunspot_rails/spec/model_lifecycle_spec.rb @@ -15,7 +15,7 @@ describe 'on update' do before :each do @post = PostWithAuto.create - @post.update_attributes(:title => 'Test 1') + @post.update(:title => 'Test 1') Sunspot.commit end diff --git a/sunspot_rails/spec/rails_app/config/boot.rb b/sunspot_rails/spec/rails_app/config/boot.rb index 4489e5868..f2830ae31 100644 --- a/sunspot_rails/spec/rails_app/config/boot.rb +++ b/sunspot_rails/spec/rails_app/config/boot.rb @@ -3,4 +3,4 @@ # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/sunspot_rails/spec/rails_app/config/storage.yml b/sunspot_rails/spec/rails_app/config/storage.yml new file mode 100644 index 000000000..09635216c --- /dev/null +++ b/sunspot_rails/spec/rails_app/config/storage.yml @@ -0,0 +1,3 @@ +test: + service: Disk + root: <%= Rails.root.join("storage") %> diff --git a/sunspot_rails/sunspot_rails.gemspec b/sunspot_rails/sunspot_rails.gemspec index a790640ef..895af22b7 100644 --- a/sunspot_rails/sunspot_rails.gemspec +++ b/sunspot_rails/sunspot_rails.gemspec @@ -30,21 +30,13 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - if RUBY_VERSION < '2.2' - s.add_dependency 'rails', '>= 3', '< 5' - else - s.add_dependency 'rails', '>= 3' - end - + s.add_dependency 'rails', '>= 5' s.add_dependency 'sunspot', Sunspot::VERSION s.add_development_dependency 'appraisal', '2.2.0' s.add_development_dependency 'bundler', '>= 1.3.0', '< 2.0' if RUBY_VERSION <= '2.0.0' s.add_development_dependency 'nokogiri', '< 1.7' if RUBY_VERSION <= '2.0.0' s.add_development_dependency 'rake', '< 12.3' - s.add_development_dependency 'rspec', '~> 3.7' - s.add_development_dependency 'rspec-rails', '~> 3.7' - s.add_development_dependency 'sqlite3', '~> 1.3.0' s.rdoc_options << '--webcvs=http://github.com/outoftime/sunspot/tree/master/%s' << '--title' << 'Sunspot-Rails - Rails integration for the Sunspot Solr search library - API Documentation' << diff --git a/sunspot_solr/lib/sunspot/solr/server.rb b/sunspot_solr/lib/sunspot/solr/server.rb index 74160c8d8..39345abc8 100644 --- a/sunspot_solr/lib/sunspot/solr/server.rb +++ b/sunspot_solr/lib/sunspot/solr/server.rb @@ -171,7 +171,7 @@ def exec_in_solr_executable_directory(command) # Boolean:: success # def install_solr_home - unless File.exists?(solr_home) + unless File.exist?(solr_home) Sunspot::Solr::Installer.execute( solr_home, :force => true, @@ -189,7 +189,7 @@ def install_solr_home # def create_solr_directories [pid_dir].each do |path| - FileUtils.mkdir_p(path) unless File.exists?(path) + FileUtils.mkdir_p(path) unless File.exist?(path) end end