# Unit Testing with ActiveRecord External Database Tables

**URL:** <https://www.ruby-forum.com/t/unit-testing-with-activerecord-external-database-tables/184374>\
**Category:** Rails\
**Created:** [March 1, 2010, 6:16pm UTC](https://www.ruby-forum.com/t/unit-testing-with-activerecord-external-database-tables/184374 "2010-03-01T18:16:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [March 1, 2010, 6:16pm UTC](https://www.ruby-forum.com/t/unit-testing-with-activerecord-external-database-tables/184374/1 "2010-03-01T18:16:21Z")

</div>

I want to perform unit tests but the model object in question is  
actually linked to an external database table. So I don’t actually have  
the database table in my local database which I need to run unit tests.  
Any ideas on how to approach this? I have created a sample fixtures yml  
file that has a subset of data from my external database table I’d like  
to use.

My setup:

I have a rake task that populates a schema based on a predefined legacy  
table. I connect to that table via:

class ExternalDBEvent \< ActiveRecord::Base  
establish\_connection :external\_db  
set\_table\_name :event  
end

I have connection parameters defined in database.yml
