# \[Bug?\] in tests, @foo.bars\_count \<\> @foo.bars.count

**URL:** <https://www.ruby-forum.com/t/bug-in-tests-foo-bars-count-foo-bars-count/50606>\
**Category:** Rails\
**Created:** [December 19, 2005, 12:52am UTC](https://www.ruby-forum.com/t/bug-in-tests-foo-bars-count-foo-bars-count/50606 "2005-12-19T00:52:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [December 19, 2005, 12:52am UTC](https://www.ruby-forum.com/t/bug-in-tests-foo-bars-count-foo-bars-count/50606/1 "2005-12-19T00:52:37Z")

</div>

Example: if a ‘foo’ has 3 ‘bars’,

bars\_count == “0” # ERROR  
bars.count == 3 # OK

It looks like a bug to me.

Alain

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [December 19, 2005, 1:20am UTC](https://www.ruby-forum.com/t/bug-in-tests-foo-bars-count-foo-bars-count/50606/2 "2005-12-19T01:20:52Z")

</div>

On 12/19/05, Alain R. [removed\_email\_address@domain.invalid](mailto: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.

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [December 19, 2005, 1:38am UTC](https://www.ruby-forum.com/t/bug-in-tests-foo-bars-count-foo-bars-count/50606/3 "2005-12-19T01:38:07Z")

</div>

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
