mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove valid_scope_name? check - use ruby
scope is syntactic sugar for defining a class method. Ruby allows redefining methods but emits a warning when run with -w. So let's not implement our own logic for this. Users should run with -w if they want to be warned about redefined methods.
This commit is contained in:
parent
884e5b7558
commit
f6db31ec16
2 changed files with 1 additions and 30 deletions
|
@ -172,10 +172,9 @@ module ActiveRecord
|
|||
# Article.featured.titles
|
||||
|
||||
def scope(name, scope_options = {})
|
||||
valid_scope_name?(name)
|
||||
extension = Module.new(&Proc.new) if block_given?
|
||||
|
||||
singleton_class.send(:redefine_method, name) do |*args|
|
||||
singleton_class.send(:define_method, name) do |*args|
|
||||
options = scope_options.respond_to?(:call) ? unscoped { scope_options.call(*args) } : scope_options
|
||||
options = scoped.apply_finder_options(options) if options.is_a?(Hash)
|
||||
|
||||
|
@ -184,15 +183,6 @@ module ActiveRecord
|
|||
extension ? relation.extending(extension) : relation
|
||||
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
|
||||
|
|
|
@ -393,25 +393,6 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
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.scoped.approved.order('id DESC')
|
||||
|
|
Loading…
Reference in a new issue