diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-04-06 13:16:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-06 13:16:01 -0400 |
commit | 7fac2b496a52f46c76090d02624f3ff53ae4bc48 (patch) | |
tree | 570675e6e46ef438121ef54548bee69c9bdc88f1 /activerecord/test | |
parent | 00f2dbd09b676f0efb38f4d1dc2d9f047d838309 (diff) | |
parent | 0bfeb481a0aa35eeca1c5230938fa61fee0faef2 (diff) | |
download | rails-7fac2b496a52f46c76090d02624f3ff53ae4bc48.tar.gz rails-7fac2b496a52f46c76090d02624f3ff53ae4bc48.tar.bz2 rails-7fac2b496a52f46c76090d02624f3ff53ae4bc48.zip |
Merge pull request #32355 from kamipo/delegate_to_klass_in_a_scope
Bring back private class methods accessibility in named scope
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/scoping/named_scoping_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index ea71a5ce28..03f8a4f7c9 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -303,6 +303,13 @@ class NamedScopingTest < ActiveRecord::TestCase assert_equal "lifo", topic.author_name end + def test_deprecated_delegating_private_method + assert_deprecated do + scope = Topic.all.by_private_lifo + assert_not scope.instance_variable_get(:@delegate_to_klass) + end + end + def test_reserved_scope_names klass = Class.new(ActiveRecord::Base) do self.table_name = "topics" diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 8cd4dc352a..fa50eeb6a4 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -12,9 +12,17 @@ class Topic < ActiveRecord::Base scope :scope_with_lambda, lambda { all } + scope :by_private_lifo, -> { where(author_name: private_lifo) } scope :by_lifo, -> { where(author_name: "lifo") } scope :replied, -> { where "replies_count > 0" } + class << self + private + def private_lifo + "lifo" + end + end + scope "approved_as_string", -> { where(approved: true) } scope :anonymous_extension, -> {} do def one |