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:
commit
9c6f348d79
3 changed files with 12 additions and 1 deletions
|
@ -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*
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue