Forum: Ruby on Rails How to configure PostgreSQL's test database before testing?

Posted by David M (Guest)
on 2012-10-24 12:09
(Received via mailing list)
My website uses PostgreSQL and its full-text search. For that to work, I
need to execute some configuration queries in order to configure some
full-text search extensions.

This is what I have written in my seeds.rb file to configure the
development database:

ActiveRecord::Base.connection.execute("CREATE EXTENSION unaccent;")
ActiveRecord::Base.connection.execute("ALTER TEXT SEARCH DICTIONARY 
unaccent (RULES='unaccent');")
ActiveRecord::Base.connection.execute("CREATE TEXT SEARCH CONFIGURATION 
es ( COPY = spanish );")
ActiveRecord::Base.connection.execute("ALTER TEXT SEARCH CONFIGURATION 
es
  ALTER MAPPING FOR hword, hword_part, word
  WITH unaccent, spanish_stem;")

This works perfectly in develpment.

Now I want to run some search tests, but when I execute my functional
tests, I get an error saying that the extension is not configured:

ActiveRecord::StatementInvalid: PG::Error: ERROR:  function 
unaccent(text) does not exist

So I assume I have to do the same that I did for development, but for 
the
test environment.

How can I do it in a clean way?
Posted by Rob Biedenharn (Guest)
on 2012-10-24 14:25
(Received via mailing list)
RAILS_ENV=test rake db:migrate

Or you might have to specify:
RAILS_ENV=test rake db:migrate:up VERSION={put your migration number 
here}

It's likely that the normal db:test:prepare task doesn't support these 
extensions.

-Rob
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.