aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_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/finder_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/finder_test.rb')
-rw-r--r--activerecord/test/cases/finder_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 3d2a03d2b9..5dc5f99582 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -666,6 +666,10 @@ class FinderTest < ActiveRecord::TestCase
assert_nil Topic.find_by_title_and_author_name("The First Topic", "Mary")
end
+ def test_find_by_two_attributes_but_passing_only_one
+ assert_raise(ArgumentError) { Topic.find_by_title_and_author_name("The First Topic") }
+ end
+
def test_find_last_by_one_attribute
assert_equal Topic.last, Topic.find_last_by_title(Topic.last.title)
assert_nil Topic.find_last_by_title("A title with no matches")
@@ -947,6 +951,10 @@ class FinderTest < ActiveRecord::TestCase
assert !another.persisted?
end
+ def test_find_or_initialize_from_two_attributes_but_passing_only_one
+ assert_raise(ArgumentError) { Topic.find_or_initialize_by_title_and_author_name("Another topic") }
+ end
+
def test_find_or_initialize_from_one_aggregate_attribute_and_one_not
new_customer = Customer.find_or_initialize_by_balance_and_name(Money.new(123), "Elizabeth")
assert_equal 123, new_customer.balance.amount