diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-10-27 09:18:06 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-10-27 09:49:50 +0100 |
commit | d616fec8117ac25753ee23e15ac14261d298ee51 (patch) | |
tree | 4d9f0e788f43518c483f25059fbbf3f59af6fb16 /activerecord/lib/active_record | |
parent | ffed7acd8eed3bc3219aad7828a54b1f2c03bfaf (diff) | |
parent | b570b6b1768f4e89b4f21526763cae77c2ff03fe (diff) | |
download | rails-d616fec8117ac25753ee23e15ac14261d298ee51.tar.gz rails-d616fec8117ac25753ee23e15ac14261d298ee51.tar.bz2 rails-d616fec8117ac25753ee23e15ac14261d298ee51.zip |
Merge pull request #17374 from maurogeorge/scope-exception
Raises ArgumentError when try to define a scope without a callable
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/scoping/named.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/scoping/named.rb b/activerecord/lib/active_record/scoping/named.rb index 49cadb66d0..ec1edf0e01 100644 --- a/activerecord/lib/active_record/scoping/named.rb +++ b/activerecord/lib/active_record/scoping/named.rb @@ -139,6 +139,10 @@ module ActiveRecord # Article.published.featured.latest_article # Article.featured.titles def scope(name, body, &block) + unless body.respond_to?:call + raise ArgumentError, 'The scope body needs to be callable.' + end + 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 " \ |