require File.dirname(__FILE__) + '/test_helper' class Product < ActiveRecord::Base end class FindersTest < Test::Unit::TestCase def test_finds_anything Product.finds :anything assert_equal 1, Product.find(1).id assert_equal 1, Product.find(123).id end def test_finds_anything_with_attributes Product.finds :anything, :name => 'muffin' p = Product.find(10) assert_equal 'muffin', p.name end def test_finds_by_id Product.finds 10 assert_equal 10, Product.find(10).id end def test_finds_by_name Product.finds_by_name 'muffin' p = Product.find_by_name('muffin') assert_equal 'muffin', p.name assert_nil Product.find_by_name('banana') end def test_finds_by_name_with_anything Product.finds :anything, :name => 'muffin' p = Product.find_by_name('muffin') assert_equal 'muffin', p.name end def test_finds_by_id_with_attributes Product.finds 1, :name => 'beer' Product.finds 10, :name => 'chips' p = Product.find(10) assert_equal 10, p.id assert_equal 'chips', p.name p = Product.find('1') assert_equal 1, p.id assert_equal 'beer', p.name end def test_find_all Product.finds 1, :name => 'beer' Product.finds 10, :name => 'chips' assert_equal [1, 10], Product.find(:all).collect(&:id) end def test_count Product.finds 1, :name => 'beer' Product.finds 10, :name => 'chips' assert_equal 2, Product.count end def test_destroy Product.finds 1, :name => 'beer' assert_equal 1, Product.count Product.find(1).destroy assert_equal 0, Product.count end def test_find_by_id_with_arguments Product.finds 1, :name => 'donut' assert_not_nil Product.find(1, :conditions => nil, :include => nil) end end