diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-17 21:34:26 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-17 21:34:41 +0530 |
commit | f0cde5be541e1f3877a15fb5d39c87a487a14381 (patch) | |
tree | 6abf7fcf3f868e3ad827f6b5ca9f6e1f3618d4bf /activerecord/lib | |
parent | 5a6596787b9489c62d149b61935057cee3dcf61a (diff) | |
download | rails-f0cde5be541e1f3877a15fb5d39c87a487a14381.tar.gz rails-f0cde5be541e1f3877a15fb5d39c87a487a14381.tar.bz2 rails-f0cde5be541e1f3877a15fb5d39c87a487a14381.zip |
Make sure named_scope names are not used as method names already
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 3f5cf68fd2..5a1cb7e769 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -99,6 +99,11 @@ module ActiveRecord # assert_equal expected_options, Shirt.colored('red').proxy_options def named_scope(name, options = {}, &block) name = name.to_sym + + if !scopes[name] && respond_to?(name, true) + raise ArgumentError, "Cannot define named_scope :#{name} because #{self.name}.#{name} method already exists." + end + scopes[name] = lambda do |parent_scope, *args| Scope.new(parent_scope, case options when Hash |