Forum: Ruby on Rails test database does not have constraints

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3f38541776a2513a20ea2f1c2d522cb3?d=identicon&s=25 Perry Smith (pedz)
on 2007-07-15 01:54
I added some db specific constraints.  I wanted to test them and tweak
them.  So, I have unit tests.  But, I was amazed to see all of the pass
the first time.

So, I looked and the test database does not have any constraints.  I'm
using PostgreSQL.  Is there an option to rake db:test:prepare ?

Thank you,
Perry
Ae82cad40a0caca9c932d45c7a9eb3cd?d=identicon&s=25 Michael Glaesemann (Guest)
on 2007-07-15 02:38
(Received via mailing list)
On Jul 14, 2007, at 18:54 , Perry Smith wrote:

> I added some db specific constraints.

> So, I looked and the test database does not have any constraints.

How did you add the db-specific constraints? I suspect you need to use
config.active_record.schema_format = :sql
in environment.rb.

Michael Glaesemann
grzm seespotcode net
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-07-15 06:40
(Received via mailing list)
Perry Smith wrote:

> I added some db specific constraints.  I wanted to test them and tweak
> them.  So, I have unit tests.  But, I was amazed to see all of the pass
> the first time.
>
> So, I looked and the test database does not have any constraints.  I'm
> using PostgreSQL.  Is there an option to rake db:test:prepare ?

I'm not sure why this isn't one tiny bit smoother, but you typically
have to
use lines like

   rake RAILS_ENV=test db:migrate
   rake RAILS_ENV=test db:test:prepare
   rake RAILS_ENV=test db:fixtures:load

You only need to do the first one, once, after adding migrations that
add
new database details. I don't think normal development requires the
second
two. The deal is 'rake test' internally switches RAILS_ENV to test mode,
but
most other rake commands do not.

In extremis (meaning very often) we must 'drop database' inside our
database
(MySquirrel) to then run db:migrate to get a fresh and up-to-date
version.

And props for unit testing!

--
  Phlip
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax
This topic is locked and can not be replied to.