# In-memory test database -- where's the schema?

**URL:** <https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554>\
**Category:** Rails\
**Created:** [January 3, 2006, 3:57am UTC](https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554 "2006-01-03T03:57:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjgp2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@mjgp2](https://www.ruby-forum.com/u/mjgp2)\
**Post date:** [January 3, 2006, 3:57am UTC](https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554/1 "2006-01-03T03:57:09Z")

</div>

I’m trying to get the unit testing for a new project to use the  
wonderful  
:memory: database specification for SQLite. However, like many people  
before me, I can’t get the schema to import or have anything else  
useful.

Initially, the error I get is:

/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/errors.rb:94:in  
`check’: cannot rollback - no transaction is active  
(SQLite3::SQLException)

Since this error seems to be transaction related, I followed the advice  
from  
another post, and turned off transactional fixtures. That changed the  
error  
message to this:

ActiveRecord::StatementInvalid: no such table: repositories: DELETE FROM  
repositories WHERE 1=1

Which certainly seems to suggest that no tables have been created in the  
memory database.

In an attempt to discover whether what I want to do is actually  
possible, I  
grepped the source for :memory:. Some of the AR unit tests do appear to  
use  
an in-memory SQLite database, but they create the tables by hand from a  
definition file (ugh).

Is there anyone who actually knows how this is supposed to work in  
Rails,  
and can provide helpful pointers as to it’s use? If not, may I suggest  
removing mention of it from the default database.yml file, to prevent  
confusion such as this in the future?

- Matt

–  
English is about as pure as a cribhouse whore. We don’t just borrow  
words; on occasion, English has pursued other languages down alleyways  
to beat them unconscious and rifle their pockets for new vocabulary."  
– James D. Nicoll, resident of rec.arts.sf.written

---

<div class="post-metadata">

**Author:** ![mjgp2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@mjgp2](https://www.ruby-forum.com/u/mjgp2)\
**Post date:** [January 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554/2 "2006-01-03T18:59:59Z")

</div>

‘me too’ - does anyone know if this used to work?

I can’t see anything obvious in trac, but this was hosed in  
Rails 1.0 for me when I tried today (sqlite3).

On 03/01/06, Matthew P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> another post, and turned off transactional fixtures. That changed the error  
> an in-memory SQLite database, but they create the tables by hand from a  
> English is about as pure as a cribhouse whore. We don’t just borrow  
> words; on occasion, English has pursued other languages down alleyways  
> to beat them unconscious and rifle their pockets for new vocabulary."  
> – James D. Nicoll, resident of rec.arts.sf.written
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rasputin :: Jack of All Trades - Master of Nuns  
[http://number9.hellooperator.net/](http://number9.hellooperator.net/)

---

<div class="post-metadata">

**Author:** ![mjgp2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@mjgp2](https://www.ruby-forum.com/u/mjgp2)\
**Post date:** [January 4, 2006, 1:00am UTC](https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554/3 "2006-01-04T01:00:51Z")

</div>

I have not really looked at the source all that closely (I am a Ruby  
n00by) but it seems that there is a problem somewhere between the  
parsing of the database.yml file and the passing of the :memory:  
parameter to sqlite. When SQLite is used like this:

ActiveRecord::Base.establish\_connection(  
:adapter =\> “sqlite”,  
:database =\> “:memory:”  
)

it works beautifully.

Hope that helps.

Dan

---

<div class="post-metadata">

**Author:** ![mjgp2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@mjgp2](https://www.ruby-forum.com/u/mjgp2)\
**Post date:** [January 3, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554/4 "2006-01-03T19:00:30Z")

</div>

On Jan 3, 2006, at 17:49, Dick D. wrote:

> ‘me too’ - does anyone know if this used to work?
> 
> I can’t see anything obvious in trac, but this was hosed in  
> Rails 1.0 for me when I tried today (sqlite3).

I reported the same issue a while back to no avail.

Could we maybe find out who committed the default in-memory for  
testing in the generated database.yml and see whether it worked for  
him? Unfortunately nobody seems to be able to test with “:memory:”.

– fxn

---

<div class="post-metadata">

**Author:** ![mjgp2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@mjgp2](https://www.ruby-forum.com/u/mjgp2)\
**Post date:** [January 4, 2006, 1:07am UTC](https://www.ruby-forum.com/t/in-memory-test-database-wheres-the-schema/51554/5 "2006-01-04T01:07:08Z")

</div>

On Jan 4, 2006, at 0:57, Daniel H. wrote:

> it works beautifully.  
> You mean the tests run? Where did you put that code?

– fxn
