#1 Fix Ruby 2.6 compatibility
Merged 5 years ago by pvalena. Opened 5 years ago by pvalena.
rpms/ pvalena/rubygem-activerecord ruby26  into  master

@@ -0,0 +1,22 @@ 

+ From 6ea356e9781e7696c48a3f9fc3ecbb0ddda5f198 Mon Sep 17 00:00:00 2001

+ From: Vladimir Dementyev <dementiev.vm@gmail.com>

+ Date: Wed, 2 Jan 2019 17:55:48 -0500

+ Subject: [PATCH] fix activerecord reaper_test

+ 

+ ---

+  activerecord/test/cases/reaper_test.rb | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb

+ index b630f782bc5b..402ddcf05a0b 100644

+ --- a/activerecord/test/cases/reaper_test.rb

+ +++ b/activerecord/test/cases/reaper_test.rb

+ @@ -48,7 +48,7 @@ def test_some_time

+  

+          reaper = ConnectionPool::Reaper.new(fp, 0.0001)

+          reaper.run

+ -        until fp.reaped

+ +        until fp.flushed

+            Thread.pass

+          end

+          assert fp.reaped

@@ -0,0 +1,26 @@ 

+ From d237c7c72ccfd87302983669f83c8c90d2aec82e Mon Sep 17 00:00:00 2001

+ From: Alberto Almagro <albertoalmagro@gmail.com>

+ Date: Fri, 4 Jan 2019 00:27:12 +0100

+ Subject: [PATCH 2/2] Make average compatible accross Ruby versions

+ 

+ Since Ruby 2.6.0 NilClass#to_d is returning `BigDecimal` 0.0, this

+ breaks `average` compatibility with prior Ruby versions. This patch

+ makes `average` return `nil` in all Ruby versions when there are no

+ rows.

+ ---

+  activerecord/lib/active_record/relation/calculations.rb | 2 +-

+  1 file changed, 1 insertion(+), 1 deletion(-)

+ 

+ diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb

+ index 3ef6e7928fcf..c2c4a5a88244 100644

+ --- a/activerecord/lib/active_record/relation/calculations.rb

+ +++ b/activerecord/lib/active_record/relation/calculations.rb

+ @@ -401,7 +401,7 @@ def type_cast_calculated_value(value, type, operation = nil)

+          case operation

+          when "count"   then value.to_i

+          when "sum"     then type.deserialize(value || 0)

+ -        when "average" then value.respond_to?(:to_d) ? value.to_d : value

+ +        when "average" then value&.respond_to?(:to_d) ? value.to_d : value

+          else type.deserialize(value)

+          end

+        end

file modified
+14 -1
@@ -4,7 +4,7 @@ 

  Name: rubygem-%{gem_name}

  Epoch: 1

  Version: 5.2.2

- Release: 1%{?dist}

+ Release: 2%{?dist}

  Summary: Object-relational mapper framework (part of Rails)

  License: MIT

  URL: http://rubyonrails.org
@@ -14,6 +14,12 @@ 

  # git checkout v5.2.2 && tar czvf activerecord-5.2.2-tests.tgz test/

  Source1: activerecord-%{version}-tests.tgz

  

+ # Backport upstream patches for Ruby 2.6 compatibility

+ # https://github.com/rails/rails/pull/34858

+ # https://github.com/rails/rails/commit/6ea356e9781e7696c48a3f9fc3ecbb0ddda5f198

+ Patch0: rubygem-activerecord-5.2.2-fix-Ruby26-compatibility.patch

+ Patch1: rubygem-activerecord-5.2.2-fix-Ruby26-compatibility-tests.patch

+ 

  # Database dump/load reuires the executable.

  Suggests: %{_bindir}/sqlite3

  BuildRequires: rubygems-devel
@@ -46,6 +52,8 @@ 

  %prep

  %setup -q -n %{gem_name}-%{version}

  

+ %patch0 -p2

+ 

  %build

  gem build ../%{gem_name}-%{version}.gemspec

  %gem_install
@@ -61,6 +69,8 @@ 

  

  tar xzvf %{SOURCE1}

  

+ cat %{PATCH1} | patch -p2 -F 0

+ 

  # Tests are broken on Fedora

  # https://github.com/rails/rails/pull/34436

  sed -i '/^\s*def test_too_many_binds$/ a skip' \
@@ -97,6 +107,9 @@ 

  %{gem_instdir}/examples

  

  %changelog

+ * Fri Jan 11 2019 Pavel Valena <pvalena@redhat.com> - 1:5.2.2-2

+ - Fix Ruby 2.6 compatibility

+ 

  * Wed Dec 05 2018 Pavel Valena <pvalena@redhat.com> - 1:5.2.2-1

  - Update to Active Record 5.2.2.

  

Backport upstream test patches for Ruby 2.6 compatibility
* Patch0: rubygem-activerecord-5.2.2-fix-Ruby26-compatibility.patch
https://github.com/rails/rails/pull/34601
* Patch1: rubygem-activerecord-5.2.2-fix-Ruby26-compatibility-tests.patch
https://github.com/rails/rails/commit/6ea356e9781e7696c48a3f9fc3ecbb0ddda5f198


Up-to-date Copr build:
https://copr.fedorainfracloud.org/coprs/build/846523

And where is the patch :blush:

rebased onto 8282eb5

5 years ago

@vondruch, yes, I missed that.

I've actually fixed the code instead of the tests, as was recommended to me.

rebased onto dc8a136

5 years ago

Thanks for checking, I'll merge this with Ruby 2.6.

EDIT: actually, I'll build it now, as it's backwards compatible and there's no need to build it with 2.6 specifically.

Pull-Request has been merged by pvalena

5 years ago