From 6e6994994d9a8edea33720f0da32b04f9a0efa2f Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sun, 17 Jul 2011 18:41:02 -0400 Subject: 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) --- activerecord/test/cases/named_scope_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/test/cases/named_scope_test.rb') 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 -- cgit v1.2.3