aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-10-08 16:45:05 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-10-09 13:03:08 +0900
commit136b738cd261a7f54f478f9fb160afb9f5e50a02 (patch)
treebc8d267763c061625939810c32d5abc3d38fcbbb /activerecord/test/models
parenta1ee4a9ff9d4a3cb255365310ead0dc7b739c6be (diff)
downloadrails-136b738cd261a7f54f478f9fb160afb9f5e50a02.tar.gz
rails-136b738cd261a7f54f478f9fb160afb9f5e50a02.tar.bz2
rails-136b738cd261a7f54f478f9fb160afb9f5e50a02.zip
Generate delegation methods to named scope in the definition time
The delegation methods to named scope are defined when `method_missing` is invoked on the relation. Since #29301, the receiver in the named scope is changed to the relation like others (e.g. `default_scope`, etc) for consistency. Most named scopes would be delegated from relation by `method_missing`, since we don't allow scopes to be defined which conflict with instance methods on `Relation` (#31179). But if a named scope is defined with the same name as any method on the `superclass` (e.g. `Kernel.open`), the `method_missing` on the relation is not invoked. To address the issue, make the delegation methods to named scope is generated in the definition time. Fixes #34098.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/account.rb13
-rw-r--r--activerecord/test/models/post.rb8
2 files changed, 16 insertions, 5 deletions
diff --git a/activerecord/test/models/account.rb b/activerecord/test/models/account.rb
index 0c3cd45a81..639e395743 100644
--- a/activerecord/test/models/account.rb
+++ b/activerecord/test/models/account.rb
@@ -11,9 +11,8 @@ class Account < ActiveRecord::Base
end
# Test private kernel method through collection proxy using has_many.
- def self.open
- where("firm_name = ?", "37signals")
- end
+ scope :open, -> { where("firm_name = ?", "37signals") }
+ scope :available, -> { open }
before_destroy do |account|
if account.firm
@@ -32,3 +31,11 @@ class Account < ActiveRecord::Base
"Sir, yes sir!"
end
end
+
+class SubAccount < Account
+ def self.instantiate_instance_of(klass, attributes, column_types = {}, &block)
+ klass = superclass
+ super
+ end
+ private_class_method :instantiate_instance_of
+end
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 528585fb75..710a75ad30 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -297,8 +297,6 @@ end
class FakeKlass
extend ActiveRecord::Delegation::DelegateCache
- inherited self
-
class << self
def connection
Post.connection
@@ -335,5 +333,11 @@ class FakeKlass
def predicate_builder
Post.predicate_builder
end
+
+ def base_class?
+ true
+ end
end
+
+ inherited self
end