aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-28 22:43:09 +0930
committerGitHub <noreply@github.com>2017-05-28 22:43:09 +0930
commit58a5aa40ec869839fc514116fb81a135050082f6 (patch)
tree7fb752b7a59f3264c61ba361421f9e9b498aed39 /activerecord
parentf4863ddb35260d9873cc535fdfbe82027622e8e6 (diff)
parent694900ec1611fb792d611f4260d94c0e060627a3 (diff)
downloadrails-58a5aa40ec869839fc514116fb81a135050082f6.tar.gz
rails-58a5aa40ec869839fc514116fb81a135050082f6.tar.bz2
rails-58a5aa40ec869839fc514116fb81a135050082f6.zip
Merge pull request #29197 from kamipo/enable_extending_even_if_scope_returns_nil
Enable extending even if scope returns nil
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/scoping/named.rb12
-rw-r--r--activerecord/test/models/topic.rb2
2 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb
index 27cdf8cb7e..029156189d 100644
--- a/activerecord/lib/active_record/scoping/named.rb
+++ b/activerecord/lib/active_record/scoping/named.rb
@@ -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
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 0420e2d15c..d9381ac9cf 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -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