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

Merge pull request #29197 from kamipo/enable_extending_even_if_scope_returns_nil

Enable extending even if scope returns nil
This commit is contained in:
Matthew Draper 2017-05-28 22:43:09 +09:30 committed by GitHub
commit 58a5aa40ec
2 changed files with 7 additions and 7 deletions

View file

@ -156,17 +156,17 @@ module ActiveRecord
if body.respond_to?(:to_proc)
singleton_class.send(:define_method, name) do |*args|
scope = all.scoping { instance_exec(*args, &body) }
scope = all
scope = scope.scoping { instance_exec(*args, &body) || scope }
scope = scope.extending(extension) if extension
scope || all
scope
end
else
singleton_class.send(:define_method, name) do |*args|
scope = all.scoping { body.call(*args) }
scope = all
scope = scope.scoping { body.call(*args) || scope }
scope = scope.extending(extension) if extension
scope || all
scope
end
end
end

View file

@ -14,7 +14,7 @@ class Topic < ActiveRecord::Base
scope :replied, -> { where "replies_count > 0" }
scope "approved_as_string", -> { where(approved: true) }
scope :anonymous_extension, -> { all } do
scope :anonymous_extension, -> {} do
def one
1
end