Skip to content

Commit a98475c

Browse files
committed
Make AR::SpawnMethods#merge! to check an arg is a Proc
From Ruby ( 2.3.0dev trunk 52520), `Hash#to_proc` is defined (ruby/ruby@fbe967e), 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`.
1 parent 5388464 commit a98475c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

activerecord/lib/active_record/relation/spawn_methods.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def spawn #:nodoc:
1212

1313
# Merges in the conditions from <tt>other</tt>, if <tt>other</tt> is an ActiveRecord::Relation.
1414
# Returns an array representing the intersection of the resulting records with <tt>other</tt>, if <tt>other</tt> is an array.
15+
#
1516
# Post.where(published: true).joins(:comments).merge( Comment.where(spam: false) )
1617
# # Performs a single join query with both where conditions.
1718
#
@@ -37,11 +38,12 @@ def merge(other)
3738
end
3839

3940
def merge!(other) # :nodoc:
40-
if !other.is_a?(Relation) && other.respond_to?(:to_proc)
41+
if other.is_a?(Hash)
42+
Relation::HashMerger.new(self, other).merge
43+
elsif other.respond_to?(:to_proc)
4144
instance_exec(&other)
4245
else
43-
klass = other.is_a?(Hash) ? Relation::HashMerger : Relation::Merger
44-
klass.new(self, other).merge
46+
Relation::Merger.new(self, other).merge
4547
end
4648
end
4749

activerecord/test/cases/relation_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def self.table_name
2424
def self.sanitize_sql_for_order(sql)
2525
sql
2626
end
27+
28+
def self.arel_table
29+
Post.arel_table
30+
end
2731
end
2832

2933
def test_construction

0 commit comments

Comments
 (0)