[DRE-commits] [rails] 03/13: fix ActiveRecord relations with Ruby 2.3
Antonio Terceiro
terceiro at moszumanska.debian.org
Fri Mar 4 18:31:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to branch master
in repository rails.
commit efd36aa9eb10055a720529b2d1607e2749003a0a
Author: Antonio Terceiro <terceiro at debian.org>
Date: Thu Mar 3 18:22:01 2016 -0300
fix ActiveRecord relations with Ruby 2.3
---
debian/changelog | 2 +
...wnMethods-merge-to-check-an-arg-is-a-Proc.patch | 66 ++++++++++++++++++++++
debian/patches/series | 1 +
3 files changed, 69 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 8966ef4..83fc1bb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,8 @@ rails (2:4.2.5.2-2) UNRELEASED; urgency=medium
* Run tests during build
- add all runtime dependencies as build dependencies as well
* Run unit tests also under autopkgtest
+ * Add 0003-Make-AR-SpawnMethods-merge-to-check-an-arg-is-a-Proc.patch to fix
+ ActiveRecord relations with Ruby 2.3
-- Antonio Terceiro <terceiro at debian.org> Thu, 03 Mar 2016 16:31:21 -0300
diff --git a/debian/patches/0003-Make-AR-SpawnMethods-merge-to-check-an-arg-is-a-Proc.patch b/debian/patches/0003-Make-AR-SpawnMethods-merge-to-check-an-arg-is-a-Proc.patch
new file mode 100644
index 0000000..d7149b0
--- /dev/null
+++ b/debian/patches/0003-Make-AR-SpawnMethods-merge-to-check-an-arg-is-a-Proc.patch
@@ -0,0 +1,66 @@
+From: yui-knk <spiketeika at gmail.com>
+Date: Wed, 11 Nov 2015 15:15:26 +0900
+Subject: Make `AR::SpawnMethods#merge!` to check an arg is a Proc
+
+>From Ruby ( 2.3.0dev trunk 52520), `Hash#to_proc` is defined
+(https://github.com/ruby/ruby/commit/fbe967ec02cb65a7efa3fb8f3d747cf6f620dde1),
+and many tests have been failed with
+`ArgumentError: wrong number of arguments (given 0, expected 1)`.
+Because we call `Hash#to_proc` with no args in `#merge!`.
+
+This commit changes order of conditionals to not call `Hash#to_proc`.
+
+(cherry picked from commit a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1)
+---
+ activerecord/lib/active_record/relation/spawn_methods.rb | 10 +++++++---
+ activerecord/test/cases/relation_test.rb | 7 +++++++
+ 2 files changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
+index 57d66bc..6551344 100644
+--- a/activerecord/lib/active_record/relation/spawn_methods.rb
++++ b/activerecord/lib/active_record/relation/spawn_methods.rb
+@@ -12,6 +12,7 @@ module ActiveRecord
+
+ # Merges in the conditions from <tt>other</tt>, if <tt>other</tt> is an <tt>ActiveRecord::Relation</tt>.
+ # Returns an array representing the intersection of the resulting records with <tt>other</tt>, if <tt>other</tt> is an array.
++ #
+ # Post.where(published: true).joins(:comments).merge( Comment.where(spam: false) )
+ # # Performs a single join query with both where conditions.
+ #
+@@ -37,11 +38,14 @@ module ActiveRecord
+ end
+
+ def merge!(other) # :nodoc:
+- if !other.is_a?(Relation) && other.respond_to?(:to_proc)
++ if other.is_a?(Hash)
++ Relation::HashMerger.new(self, other).merge
++ elsif other.is_a?(Relation)
++ Relation::Merger.new(self, other).merge
++ elsif other.respond_to?(:to_proc)
+ instance_exec(&other)
+ else
+- klass = other.is_a?(Hash) ? Relation::HashMerger : Relation::Merger
+- klass.new(self, other).merge
++ raise ArgumentError, "#{other.inspect} is not an ActiveRecord::Relation"
+ end
+ end
+
+diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
+index 408953b..44e07a2 100644
+--- a/activerecord/test/cases/relation_test.rb
++++ b/activerecord/test/cases/relation_test.rb
+@@ -260,6 +260,13 @@ module ActiveRecord
+ assert_equal 3, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count.length
+ end
+
++ def test_merge_raises_with_invalid_argument
++ assert_raises ArgumentError do
++ relation = Relation.new(FakeKlass, :b)
++ relation.merge(true)
++ end
++ end
++
+ class EnsureRoundTripTypeCasting < ActiveRecord::Type::Value
+ def type
+ :string
diff --git a/debian/patches/series b/debian/patches/series
index 4b2ab0b..638054b 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
0001-Be-careful-with-that-bundler.patch
0002-load_paths.rb-don-t-load-bundler.patch
+0003-Make-AR-SpawnMethods-merge-to-check-an-arg-is-a-Proc.patch
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/rails.git
More information about the Pkg-ruby-extras-commits
mailing list