提交 dc925119 编写于 作者: A Akira Matsuda

Revert "Remove valid_scope_name? check - use ruby"

This reverts commit f6db31ec.

Reason:
Scope names can very easily conflict, particularly when sharing Concerns
within the team, or using multiple gems that extend AR models.

It is true that Ruby has the ability to detect this with the -w option, but the
reality is that we are depending on too many gems that do not care about Ruby
warnings, therefore it might not be a realistic solution to turn this switch on
in our real-world apps.
上级 a6928161
......@@ -151,6 +151,7 @@ def scope(name, body, &block)
"a class method with the same name."
end
valid_scope_name?(name)
extension = Module.new(&block) if block
if body.respond_to?(:to_proc)
......@@ -169,6 +170,15 @@ def scope(name, body, &block)
end
end
end
protected
def valid_scope_name?(name)
if respond_to?(name, true)
logger.warn "Creating scope :#{name}. " \
"Overwriting existing method #{self.name}.#{name}."
end
end
end
end
end
......
......@@ -440,6 +440,25 @@ def test_table_names_for_chaining_scopes_with_and_without_table_name_included
end
end
def test_scopes_with_reserved_names
class << Topic
def public_method; end
public :public_method
def protected_method; end
protected :protected_method
def private_method; end
private :private_method
end
[:public_method, :protected_method, :private_method].each do |reserved_method|
assert Topic.respond_to?(reserved_method, true)
ActiveRecord::Base.logger.expects(:warn)
Topic.scope(reserved_method)
end
end
def test_scopes_on_relations
# Topic.replied
approved_topics = Topic.all.approved.order('id DESC')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册