diff options
author | yui-knk <spiketeika@gmail.com> | 2015-11-11 15:15:26 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2015-11-12 11:02:49 +0900 |
commit | a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1 (patch) | |
tree | 10b90a72d3af01d54876b4632432b0fb7db993d0 /activerecord/lib/active_record | |
parent | 5388464af6ec229ddf3a1040cd7466f45370cedd (diff) | |
download | rails-a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1.tar.gz rails-a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1.tar.bz2 rails-a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1.zip |
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`.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 5c3318651a..ee509b98d4 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 ActiveRecord::Relation. # 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,12 @@ 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.respond_to?(:to_proc) instance_exec(&other) else - klass = other.is_a?(Hash) ? Relation::HashMerger : Relation::Merger - klass.new(self, other).merge + Relation::Merger.new(self, other).merge end end |