aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/scoping
diff options
context:
space:
mode:
authorMauro George <maurogot@gmail.com>2014-10-23 19:48:12 -0200
committerMauro George <maurogot@gmail.com>2014-10-23 19:48:12 -0200
commitb570b6b1768f4e89b4f21526763cae77c2ff03fe (patch)
tree9afbb1a60ff5c6426d00da6bf09e31766a2271ca /activerecord/lib/active_record/scoping
parentbe49ec4b1f4256146b963a781a02748a342c6b6e (diff)
downloadrails-b570b6b1768f4e89b4f21526763cae77c2ff03fe.tar.gz
rails-b570b6b1768f4e89b4f21526763cae77c2ff03fe.tar.bz2
rails-b570b6b1768f4e89b4f21526763cae77c2ff03fe.zip
Raises ArgumentError when try to define a scope without a callable
This changes the actual exception `NoMethodError: undefined method `call' for #<ActiveRecord::Relation []>` to a `ArgumentError` when try to define a scope without a callable.
Diffstat (limited to 'activerecord/lib/active_record/scoping')
-rw-r--r--activerecord/lib/active_record/scoping/named.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb
index 49cadb66d0..04aeeeb4fa 100644
--- a/activerecord/lib/active_record/scoping/named.rb
+++ b/activerecord/lib/active_record/scoping/named.rb
@@ -139,6 +139,9 @@ module ActiveRecord
# Article.published.featured.latest_article
# Article.featured.titles
def scope(name, body, &block)
+ raise ArgumentError, 'You need to suply a callable as scope body' unless
+ body.respond_to?(:call)
+
if dangerous_class_method?(name)
raise ArgumentError, "You tried to define a scope named \"#{name}\" " \
"on the model \"#{self.name}\", but Active Record already defined " \