1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #25849 from suginoy/fix_merge_in_scope

Fix the calling `merge` method at first in a scope
This commit is contained in:
Rafael Mendonça França 2016-07-20 02:11:17 -03:00
commit 9c6f348d79
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
3 changed files with 12 additions and 1 deletions

View file

@ -1,3 +1,7 @@
* Support calling the method `merge` in `scope`'s lambda.
*Yasuhiro Sugino*
* Fixes multi-parameter attributes conversion with invalid params. * Fixes multi-parameter attributes conversion with invalid params.
*Hiroyuki Ishii* *Hiroyuki Ishii*

View file

@ -9,7 +9,7 @@ module ActiveRecord
delegate :find_each, :find_in_batches, :in_batches, to: :all delegate :find_each, :find_in_batches, :in_batches, to: :all
delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins, :left_joins, :left_outer_joins, :or, delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins, :left_joins, :left_outer_joins, :or,
:where, :rewhere, :preload, :eager_load, :includes, :from, :lock, :readonly, :where, :rewhere, :preload, :eager_load, :includes, :from, :lock, :readonly,
:having, :create_with, :uniq, :distinct, :references, :none, :unscope, to: :all :having, :create_with, :uniq, :distinct, :references, :none, :unscope, :merge, to: :all
delegate :count, :average, :minimum, :maximum, :sum, :calculate, to: :all delegate :count, :average, :minimum, :maximum, :sum, :calculate, to: :all
delegate :pluck, :ids, to: :all delegate :pluck, :ids, to: :all

View file

@ -46,6 +46,13 @@ class NamedScopingTest < ActiveRecord::TestCase
assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count) assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
end end
def test_calling_merge_at_first_in_scope
Topic.class_eval do
scope :calling_merge_at_first_in_scope, Proc.new { merge(Topic.replied) }
end
assert_equal Topic.calling_merge_at_first_in_scope.to_a, Topic.replied.to_a
end
def test_method_missing_priority_when_delegating def test_method_missing_priority_when_delegating
klazz = Class.new(ActiveRecord::Base) do klazz = Class.new(ActiveRecord::Base) do
self.table_name = "topics" self.table_name = "topics"