aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-02-02 05:00:15 -0200
committerRafael França <rafaelmfranca@gmail.com>2016-02-02 05:00:15 -0200
commit7710d7f432ca776885a346346ccf0971e80b7a34 (patch)
treee248680e2fcaf9aa5d9458da36be36edbbc57704 /activerecord/lib
parent2c7bc9251c41db15514fba6b9c03e41cd6232433 (diff)
parent2812af720e4869f03e836d1b527b0a50c2a52b22 (diff)
downloadrails-7710d7f432ca776885a346346ccf0971e80b7a34.tar.gz
rails-7710d7f432ca776885a346346ccf0971e80b7a34.tar.bz2
rails-7710d7f432ca776885a346346ccf0971e80b7a34.zip
Merge pull request #23331 from amatsuda/valid_scope_name
Warn if a named scope is overwriting an existing scope or method
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/scoping/named.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb
index 103569c84d..5395bd6076 100644
--- a/activerecord/lib/active_record/scoping/named.rb
+++ b/activerecord/lib/active_record/scoping/named.rb
@@ -151,6 +151,7 @@ module ActiveRecord
"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 @@ module ActiveRecord
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