diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-24 06:25:09 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-24 06:39:20 +0900 |
commit | 694900ec1611fb792d611f4260d94c0e060627a3 (patch) | |
tree | 4734586f404756016f0f13e31ebaa32d24d7c63a /activerecord | |
parent | 845aabbcd3805420090f8b92b50a4562577cf210 (diff) | |
download | rails-694900ec1611fb792d611f4260d94c0e060627a3.tar.gz rails-694900ec1611fb792d611f4260d94c0e060627a3.tar.bz2 rails-694900ec1611fb792d611f4260d94c0e060627a3.zip |
Enable extending even if scope returns nil
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 12 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 2 |
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 |