Forum: Ruby on Rails #find(:all) not finding all from fixture -- help?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
peter.fitzgibbons (Guest)
on 2005-11-14 18:29
(Received via mailing list)
Hello all,
please review the code parts here :
http://rafb.net/paste/results/CZTw2063.html
Briefly: Buyer belongs_to :family and :user. User has_one :buyer. Family
has_many :buyer.

When I run this test :


class BuyerTest < Test::Unit::TestCase

def test_yaml
assert_not_nil Buyer.find(4000)
assert_not_nil Buyer.find(4001)

assert_equal 2, Buyer.find(:all)
end
end

I get this failure :


Loaded suite C:/ruby/dev/buildview2/test/unit/buyer_test
Started
.F
Finished in 0.562 seconds.

1) Failure:

test_yaml(BuyerTest)
[C:/ruby/dev/buildview2/test/unit/buyer_test.rb:13]:test_yaml(BuyerTest)
[C:/ruby/dev/buildview2/test/unit/buyer_test.rb:13]:

<2> expected but was

<[#<Buyer:0x3a0c9a0
@attributes=
{"family_id"=>5000,
"created_on"=>"2005/01/01 00:00:00",
"work_phone"=>"(123) 123-1231",
"city"=>"Buyer City",
"postal_code"=>"12345",
"email_active"=>1,
"region"=>"IL",
"updated_on"=>"2005/01/01 00:00:00",
"ssn"=>"123121233",
"lock_version"=>0,
"country"=>"USA",
"id"=>4000,
"cell_phone"=>"(123) 123-1231",
"address_line_1"=>"Buyer Address 1",
"sex"=>"M",
"home_phone"=>"(123) 123-1231",
"address_line_2"=>"Buyer Address 2",
"user_id"=>1,
"date_of_birth"=>nil,
"first_name"=>"Bob",
"last_name"=>"Buyer",
"middle_name"=>"",
"email"=>"removed_email_address@domain.invalid"}>,
#<Buyer:0x3a0c940
@attributes=
{"family_id"=>5000,
"created_on"=>"2005/01/01 00:00:00",
"work_phone"=>"(123) 123-1231",
"city"=>"Buyer City",
"postal_code"=>"12345",
"email_active"=>1,
"region"=>"IL",
"updated_on"=>"2005/01/01 00:00:00",
"ssn"=>"123121233",
"lock_version"=>0,
"country"=>"USA",
"id"=>4001,
"cell_phone"=>"(123) 123-1231",
"address_line_1"=>"Buyer Address 1",
"sex"=>"F",
"home_phone"=>"(123) 123-1231",
"address_line_2"=>"Buyer Address 2",
"user_id"=>5,
"date_of_birth"=>nil,
"first_name"=>"Mary",
"last_name"=>"Buyer",
"middle_name"=>"",
"email"=>"removed_email_address@domain.invalid"}>]>.
2 tests, 10 assertions, 1 failures, 0 errors

Please tell me I'm missing something very very obvious?
graeme.nelson (Guest)
on 2005-11-14 18:38
(Received via mailing list)
Hi Peter -

It looks like you are comparing the value 2 against an array that comes
back. You should
probably ask for the size of the array in this case.

assert_equal 2, Buyer.find(:all).size

Thanks
graeme
codyfauser (Guest)
on 2005-11-14 18:41
(Received via mailing list)
Peter,

You could also use:
assert_equal 2, Buyer.count


Cody
peter.fitzgibbons (Guest)
on 2005-11-14 18:47
(Received via mailing list)
HI Graeme,
 Thank you! Some days I am just not in the Ruby Way.
This topic is locked and can not be replied to.