From 3019fbdf179b4687eef5b99a93592e3c1d36a77f Mon Sep 17 00:00:00 2001 From: Philipp Bayer Date: Fri, 2 Dec 2022 19:42:38 +0800 Subject: [PATCH] Update ruby to 2.7.7 (#549) * Update Ruby to 2.7.7, add bigdecimal and scanf, update webmock, monkeypatch tests to work with Rails 4.2 --- .ruby-version | 2 +- Gemfile | 9 +++++- Gemfile.lock | 20 ++++++++------ spec/support/patch.rb | 64 +++++++++++++++++++++++++++++++++++++++++++ test/test_helper.rb | 56 +++++++++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 spec/support/patch.rb diff --git a/.ruby-version b/.ruby-version index aedc15b..1f7da99 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.3 +2.7.7 diff --git a/Gemfile b/Gemfile index b35cee6..6b84f4b 100644 --- a/Gemfile +++ b/Gemfile @@ -57,6 +57,13 @@ gem 'sass-rails' # monitoring gem 'sentry-raven' +# get rid of Ruby 2.7.7 error +# bigdecimal is required by ActiveSupport, and bigdecimal 2 +# introduces some breaking changes (You cannot use BigDecimal.new) +gem 'bigdecimal', '1.3.5' +# Ruby 2.7.0 does not include scanf +gem 'scanf' + #group :production do # gem 'rpm_contrib' #end @@ -68,7 +75,7 @@ group :test do gem 'shoulda-context' gem 'mocha', require: false gem 'simplecov', require: false - gem 'webmock' + gem 'webmock', '>= 3.5.0' # need at least 3.5.0 for Ruby 2.6 gem 'vcr' gem 'capybara' gem 'poltergeist' diff --git a/Gemfile.lock b/Gemfile.lock index 2796255..ecf0fb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,6 +80,7 @@ GEM bcrypt (3.1.16) bcrypt-ruby (3.1.5) bcrypt (>= 3.1.3) + bigdecimal (1.3.5) builder (3.2.4) capistrano (2.15.9) highline @@ -103,8 +104,8 @@ GEM activerecord (~> 4.2.0) concurrent-ruby (1.1.9) connection_pool (2.2.1) - crack (0.4.3) - safe_yaml (~> 1.0.0) + crack (0.4.5) + rexml crass (1.0.6) database_cleaner (1.6.2) diff-lcs (1.3) @@ -149,7 +150,7 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - hashdiff (0.3.7) + hashdiff (1.0.1) highline (1.7.10) http-accept (1.7.0) http-cookie (1.0.5) @@ -284,6 +285,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + rexml (3.2.5) rspec (3.7.0) rspec-core (~> 3.7.0) rspec-expectations (~> 3.7.0) @@ -309,7 +311,6 @@ GEM rubyzip (1.3.0) rvm-capistrano (1.4.4) capistrano (>= 2.15.4) - safe_yaml (1.0.4) sanitize (5.2.1) crass (~> 1.0.2) nokogiri (>= 1.8.0) @@ -325,6 +326,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + scanf (1.0.0) scrypt (3.0.5) ffi-compiler (>= 1.0, < 2.0) selenium-webdriver (3.142.7) @@ -386,10 +388,10 @@ GEM unf_ext (0.0.8.2) uuidtools (2.1.5) vcr (4.0.0) - webmock (3.3.0) + webmock (3.13.0) addressable (>= 2.3.6) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -410,6 +412,7 @@ DEPENDENCIES attr_encrypted authlogic bcrypt-ruby + bigdecimal (= 1.3.5) capistrano (~> 2.0) capybara composite_primary_keys (~> 8.0) @@ -446,6 +449,7 @@ DEPENDENCIES rvm-capistrano (= 1.4.4) sanitize sass-rails + scanf selenium-webdriver sentry-raven shoulda-context @@ -463,10 +467,10 @@ DEPENDENCIES uglifier uuidtools vcr - webmock + webmock (>= 3.5.0) whenever will_paginate will_paginate-bootstrap BUNDLED WITH - 1.17.3 + 2.0.0.pre.3 diff --git a/spec/support/patch.rb b/spec/support/patch.rb new file mode 100644 index 0000000..841823a --- /dev/null +++ b/spec/support/patch.rb @@ -0,0 +1,64 @@ +# From https://github.com/rails/rails/issues/34790 +# +# This is required because of an incompatibility between Ruby 2.6 and Rails 4.2, which the Rails team is not going to fix. + +rb_version = Gem::Version.new(RUBY_VERSION) + +if rb_version >= Gem::Version.new('2.6') && Gem::Version.new(Rails.version) < Gem::Version.new('5') + if ! defined?(::ActionController::TestResponse) + raise "Needed class is not defined yet, try requiring this file later." + end + + if rb_version >= Gem::Version.new('2.7') + puts "Using #{__FILE__} for Ruby 2.7." + + class ActionController::TestResponse < ActionDispatch::TestResponse + def recycle! + @mon_data = nil + @mon_data_owner_object_id = nil + initialize + end + end + + class ActionController::LiveTestResponse < ActionController::Live::Response + def recycle! + @body = nil + @mon_data = nil + @mon_data_owner_object_id = nil + initialize + end + end + + else + puts "Using #{__FILE__} for Ruby 2.6." + + class ActionController::TestResponse < ActionDispatch::TestResponse + def recycle! + @mon_mutex = nil + @mon_mutex_owner_object_id = nil + initialize + end + end + + class ActionController::LiveTestResponse < ActionController::Live::Response + def recycle! + @body = nil + @mon_mutex = nil + @mon_mutex_owner_object_id = nil + initialize + end + end + + class ActionController::TestCase < ActiveSupport::TestCase + def recycle! + @body = nil + @mon_data = nil + @mon_data_owner_object_id = nil + initialize + end + end + + end +else + puts "#{__FILE__} no longer needed." +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1da6343..5572f22 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -29,3 +29,59 @@ class ActiveSupport::TestCase include Authlogic::TestCase include WebMock::API end + +# From https://github.com/rails/rails/issues/34790 +# +# This is required because of an incompatibility between Ruby 2.6 and Rails 4.2, which the Rails team is not going to fix. + +rb_version = Gem::Version.new(RUBY_VERSION) + +if rb_version >= Gem::Version.new('2.6') && Gem::Version.new(Rails.version) < Gem::Version.new('5') + if ! defined?(::ActionController::TestResponse) + raise "Needed class is not defined yet, try requiring this file later." + end + + if rb_version >= Gem::Version.new('2.7') + puts "Using #{__FILE__} for Ruby 2.7." + + class ActionController::TestResponse < ActionDispatch::TestResponse + def recycle! + @mon_data = nil + @mon_data_owner_object_id = nil + initialize + end + end + + class ActionController::LiveTestResponse < ActionController::Live::Response + def recycle! + @body = nil + @mon_data = nil + @mon_data_owner_object_id = nil + initialize + end + end + + else + puts "Using #{__FILE__} for Ruby 2.6." + + class ActionController::TestResponse < ActionDispatch::TestResponse + def recycle! + @mon_mutex = nil + @mon_mutex_owner_object_id = nil + initialize + end + end + + class ActionController::LiveTestResponse < ActionController::Live::Response + def recycle! + @body = nil + @mon_mutex = nil + @mon_mutex_owner_object_id = nil + initialize + end + end + + end +else + puts "#{__FILE__} no longer needed." +end