# Rspec and validates\_existence\_of

**URL:** <https://www.ruby-forum.com/t/rspec-and-validates-existence-of/136941>\
**Category:** Rails\
**Created:** [May 7, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/rspec-and-validates-existence-of/136941 "2008-05-07T16:20:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rory\_McKinley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@Rory\_McKinley](https://www.ruby-forum.com/u/Rory_McKinley)\
**Post date:** [May 7, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/rspec-and-validates-existence-of/136941/1 "2008-05-07T16:20:04Z")

</div>

Hi List

I am using validates\_existence\_of in some of my Model classes. For  
instance I have the following class:

class User \< ActiveRecord::Base  
belongs\_to :department

```
 validates_existence_of :department

```

end

If I create an instance of User in the console and set the department to  
be one that does not exist in the db, then a call to valid? returns  
false.

However, if I create a rspec test block, that does something similar,  
then valid? returns true. It is almost as if rspec is ignoring the  
validates\_existence\_of. Does naybody have any ideas how to fix this?

Thanks in advance

Rory
