From 0591c53efde948fd49a00aa23bdfc2ca26fca434 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 17 Apr 2005 17:16:24 +0000 Subject: Made the dynamic finders use the new find API and updated the examples here and there git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1196 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/deprecated_finder_test.rb | 9 +++++++++ activerecord/test/finder_test.rb | 15 ++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/deprecated_finder_test.rb b/activerecord/test/deprecated_finder_test.rb index c9bf7c7f43..422e17747d 100755 --- a/activerecord/test/deprecated_finder_test.rb +++ b/activerecord/test/deprecated_finder_test.rb @@ -127,6 +127,15 @@ class FinderTest < Test::Unit::TestCase assert_equal 'fixture_9', last_two_developers.first.name end + def test_find_all_by_one_attribute_with_options + topics = Topic.find_all_by_content("Have a nice day", nil, "id DESC") + assert @topics["first"].find, topics.last + + topics = Topic.find_all_by_content("Have a nice day", nil, "id DESC") + assert @topics["first"].find, topics.first + end + + protected def bind(statement, *vars) if vars.first.is_a?(Hash) diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index dd8e8b5487..0c672c2e35 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -202,6 +202,14 @@ class FinderTest < Test::Unit::TestCase assert_equal [], Topic.find_all_by_title("The First Topic!!") end + + def test_find_all_by_one_attribute_with_options + topics = Topic.find_all_by_content("Have a nice day", :order => "id DESC") + assert @topics["first"].find, topics.last + + topics = Topic.find_all_by_content("Have a nice day", :order => "id") + assert @topics["first"].find, topics.first + end def test_find_all_by_boolean_attribute topics = Topic.find_all_by_approved(false) @@ -241,16 +249,13 @@ class FinderTest < Test::Unit::TestCase end def test_find_all_with_limit - first_five_developers = Developer.find_all nil, 'id ASC', 5 + first_five_developers = Developer.find :all, :order => 'id ASC', :limit => 5 assert_equal 5, first_five_developers.length assert_equal 'David', first_five_developers.first.name assert_equal 'fixture_5', first_five_developers.last.name - no_developers = Developer.find_all nil, 'id ASC', 0 + no_developers = Developer.find :all, :order => 'id ASC', :limit => 0 assert_equal 0, no_developers.length - - assert_equal first_five_developers, Developer.find_all(nil, 'id ASC', [5]) - assert_equal no_developers, Developer.find_all(nil, 'id ASC', [0]) end def test_find_all_with_limit_and_offset -- cgit v1.2.3