# Unit Testing - Examining Database Records

**URL:** <https://www.ruby-forum.com/t/unit-testing-examining-database-records/121688>\
**Category:** Rails\
**Created:** [November 29, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/unit-testing-examining-database-records/121688 "2007-11-29T23:02:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alan](https://www.ruby-forum.com/u/alan)\
**Post date:** [November 29, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/unit-testing-examining-database-records/121688/1 "2007-11-29T23:02:31Z")

</div>

I am creating some unit test for class methods which create/update  
records in one or more tables.  
What is the best way to check that this is done and assert the  
results?

I would expect something like an unordered array of hashes compare  
(with what I think should be in the db with what is in the db), but  
before I build this myself is there something about this already  
done? I’ve googled everywhere but all I find are validation test  
examples.

Thanks!

---

<div class="post-metadata">

**Author:** ![alan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alan](https://www.ruby-forum.com/u/alan)\
**Post date:** [November 30, 2007, 7:48pm UTC](https://www.ruby-forum.com/t/unit-testing-examining-database-records/121688/2 "2007-11-30T19:48:59Z")

</div>

I am (admittedly slowly) posting a multi-part tutorial on testing.  
I’m hoping not just to make testing easy and less intimidating to  
beginners, but also to examine what to test and how to write  
meaningful tests.

I will be writing about unit testing ActiveRecord models next. (Maybe  
by early next week?) It may answer your questions.

The series starts here:  
[http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/](http://www.nullislove.com/2007/11/10/testing-in-rails-introduction/)

HTH,  
Kevin S.
