aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/named_scope_test.rb
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2011-07-17 18:41:02 -0400
committerPrem Sichanugrist <s@sikachu.com>2011-07-17 18:44:03 -0400
commit6e6994994d9a8edea33720f0da32b04f9a0efa2f (patch)
tree5bf702910dbe0accd9be6c79b5b9112c9dc2aa6a /activerecord/test/cases/named_scope_test.rb
parente9bd83402ed1ab86e70c9ec6ffc913b72fd41f1d (diff)
downloadrails-6e6994994d9a8edea33720f0da32b04f9a0efa2f.tar.gz
rails-6e6994994d9a8edea33720f0da32b04f9a0efa2f.tar.bz2
rails-6e6994994d9a8edea33720f0da32b04f9a0efa2f.zip
Raise an ArgumentError if user passing less number of argument in the dynamic finder
The previous behavior was unintentional, and some people was relying on it. Now the dynamic finder will always expecting the number of arguments to be equal or greater (so you can still pass the options to it.) So if you were doing this and expecting the second argument to be nil: User.find_by_username_and_group("sikachu") You'll now get `ArgumentError: wrong number of arguments (1 for 2).` You'll then have to do this: User.find_by_username_and_group("sikachu", nil)
Diffstat (limited to 'activerecord/test/cases/named_scope_test.rb')
-rw-r--r--activerecord/test/cases/named_scope_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 2afe3c8f32..01893e4dc3 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -497,6 +497,17 @@ end
class DynamicScopeTest < ActiveRecord::TestCase
fixtures :posts
+ def setup
+ # Ensure we start with a clean model with no generated class method
+ Post.methods.select{ |c| c =~ /scoped_by_/ }.each do |method_name|
+ Post.class_eval <<-RUBY
+ class << self
+ remove_method :#{method_name}
+ end
+ RUBY
+ end
+ end
+
def test_dynamic_scope
assert_equal Post.scoped_by_author_id(1).find(1), Post.find(1)
assert_equal Post.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, Post.find(:first, :conditions => { :author_id => 1, :title => "Welcome to the weblog"})
@@ -507,4 +518,8 @@ class DynamicScopeTest < ActiveRecord::TestCase
Developer.scoped_by_created_at(nil)
assert_present Developer.methods.grep(/scoped_by_created_at/)
end
+
+ def test_dynamic_scope_with_less_number_of_arguments
+ assert_raise(ArgumentError){ Post.scoped_by_author_id_and_title(1) }
+ end
end