Re: Strange Little Problem

Bob Showalter
Wed, 26 Sep 2007 18:34:59 -0000

On 9/25/07, qb <jkordyback-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
> If I remove " require ''member'' " from the test
case then everything
> passes. I have no idea why. (Yes I''m a newbie, please
don''t laugh and
> point). I''m digging through ActiveRecord, UnitTest, and Ruby docs
and
> source but haven''t found an answer yet. Any ideas?

As Rob pointed out, it''s being caused by your model file being loaded
twice, and thus the validates_uniqueness_of being run twice. You end
up getting two (identical) error messages.

The "second" load of your model file is actually coming from the
"fixtures" line, which ends up calling:

   require_dependency ''member''

In order for require_dependency to do it''s magic, it has to turn your
file name into an absolute path. So you get the effect of:

   require ''member''
   require ''/some/absolute/path/to/member.rb''

Ruby doesn''t know that these are the same file, so it ends up loading
the file twice, thus doubling the validates declarations.

So, the short answer is: don''t "require" your models in your
test
cases (or use require_dependency).