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.
B45eab4f18aa1bb2a44d6e657531a642?d=identicon&s=25 Alain Ravet (aravet)
on 2005-12-19 00:52
Example: if a 'foo' has  3 'bars',

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

It looks like a bug to me.

Alain
3bec49196b296ac7c201412642c7a2b1?d=identicon&s=25 =?ISO-8859-1?Q?Rodrigo_Alvarez_Fern=E1ndez?= (Guest)
on 2005-12-19 01:20
(Received via mailing list)
On 12/19/05, Alain Ravet <alainravet-spam2004@yahoo.com> 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.
B45eab4f18aa1bb2a44d6e657531a642?d=identicon&s=25 Alain Ravet (aravet)
on 2005-12-19 01:38
Alain Ravet 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.