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.
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 peter.fitzgibbons (Guest)
on 2005-11-14 17: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"=>"bob@test.com"}>,
#<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"=>"mary@test.com"}>]>.
2 tests, 10 assertions, 1 failures, 0 errors

Please tell me I'm missing something very very obvious?
D5eed3431d2ce4e6f0469b8804458d8a?d=identicon&s=25 graeme.nelson (Guest)
on 2005-11-14 17: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
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 codyfauser (Guest)
on 2005-11-14 17:41
(Received via mailing list)
Peter,

You could also use:
assert_equal 2, Buyer.count


Cody
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 peter.fitzgibbons (Guest)
on 2005-11-14 17: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.