Forum: Ruby on Rails [Bug?] in tests, @foo.bars_count <> @foo.bars.count

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.
Alain R. (Guest)
on 2005-12-19 01:52
Example: if a 'foo' has  3 'bars',

   bars_count == "0"   # ERROR
   bars.count == 3     # OK

It looks like a bug to me.

Alain
=?ISO-8859-1?Q?Rodrigo_Alvarez_Fern=E1ndez?= (Guest)
on 2005-12-19 02:20
(Received via mailing list)
On 12/19/05, Alain R. <removed_email_address@domain.invalid> wrote:
>
> Example: if a 'foo' has  3 'bars',
>
>    bars_count == "0"   # ERROR
>    bars.count == 3     # OK


And what about collection.size and collection_count? Which should be
used
and in what case?

It looks like a bug to me.
Alain R. (Guest)
on 2005-12-19 02:38
Alain R. wrote:
  >    bars_count == "0"   # ERROR
  >    bars.count == 3     # OK

I should have added that I use a count cache on the "foo" table.
     => there is a "bars_count" column in the 'foo' table,
BUT
   I didn't initialize it, as the bars are added in another fixture:
bars.yml

=> my test class starts with
   fixture  :foos, :bars

It looks like counters caches are not initialized by fixtures.

Alain
This topic is locked and can not be replied to.