# My Unit Tests are using outdated Model Data

**URL:** <https://www.ruby-forum.com/t/my-unit-tests-are-using-outdated-model-data/205098>\
**Category:** Rails\
**Created:** [March 29, 2011, 8:18pm UTC](https://www.ruby-forum.com/t/my-unit-tests-are-using-outdated-model-data/205098 "2011-03-29T20:18:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 29, 2011, 8:18pm UTC](https://www.ruby-forum.com/t/my-unit-tests-are-using-outdated-model-data/205098/1 "2011-03-29T20:18:18Z")

</div>

Hello, I’m new to Rails 3 and its unit testing capabilities.

I’ve created a simple unit test just to see if I could get it to run  
correctly:

class CaseTest \< ActiveSupport::TestCase

# Replace this with your real tests.

test “the truth” do  
assert\_equal 2,2  
end  
end

But when I run that test with: ruby -I test test/unit/case\_test.rb, it  
appears to be calling that unit test but is getting a Postgres  
insertion error on a model that I’ve changed awhile ago (I removed the  
column ‘title’ awhile ago and migrated which has been working fine for  
me in my development environment):

1.) Error:  
test\_the\_truth(CaseTest):  
ActiveRecord::StatementInvalid: PGError: ERROR: column “title” of  
relation “questions” does not exist  
LINE 1: INSERT INTO “questions” (“title”, “body”, “created\_at”,  
"upd…

I have two questions.

First, why is it even attempting to insert a new question when I’m  
just trying to test if 2 is the same as 2?  
Second, given that it is trying to insert a question for some reason,  
why is it using outdated model info?

Thanks for any help you can give.

---

<div class="post-metadata">

**Author:** ![LennonR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e79b87/32.png) [@LennonR](https://www.ruby-forum.com/u/LennonR)\
**Post date:** [March 29, 2011, 8:36pm UTC](https://www.ruby-forum.com/t/my-unit-tests-are-using-outdated-model-data/205098/2 "2011-03-29T20:36:55Z")

</div>

On 29 Mar 2011, at 19:06, LennonR [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> relation “questions” does not exist  
> why is it using outdated model info?
> 
> Thanks for any help you can give.

Do you have a fixtures file that is being loaded automatically?

Fred

---

<div class="post-metadata">

**Author:** ![LennonR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e79b87/32.png) [@LennonR](https://www.ruby-forum.com/u/LennonR)\
**Post date:** [March 29, 2011, 10:49pm UTC](https://www.ruby-forum.com/t/my-unit-tests-are-using-outdated-model-data/205098/3 "2011-03-29T22:49:50Z")

</div>

Ah, yes, that’s the problem. I assumed that all the generated  
fixtures would be empty but I see now that Rails created some test  
data. And this data was from when I originally generated my models  
(since changed).

And I see now that, according to my Rails Unit Testing Guide: “Rails  
by default automatically loads all fixtures from the test/fixtures  
folder for your unit and functional test”

So I see it was trying to populate the db with the old table.

On Mar 29, 2:34pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
