0

I'm using postgresql on a rails 3 app. I've been using sqlite3 for test environment, but decided to finally switch to the same db I use in production for testing purposes. Problem is, I'm only creating one database and diverse schemas for each environment. This is somethiing I can't change, since the environment is enterprise-constrained.

Hence, I have a test schema. I rund db:schema:load on it and it works fine. I run rake spec on it (I'm using rspec) and it breaks, exactly on the 'db:test:purge' task which comes from rails. Now, this task drops the database. Not only is the database owner different from the schema owner in my case, I'd rather have the task recreate the schema instead of recreating the database.

How can I do this?

ChuckE
  • 5,610
  • 4
  • 31
  • 59
  • this might help you… http://stackoverflow.com/a/6332189/832759 normally I use `database_cleaner` for clean up my test database but I'm not sure if it would work for your case… https://github.com/bmabey/database_cleaner – j03w Sep 02 '13 at 09:37
  • sorry, but database_cleaner doesn't have anything to do with it. I'm talking about a rake task being invoked as a before callback from the rake spec task. I'm already using database_cleaner to clean tables in between specs. – ChuckE Sep 02 '13 at 11:14

2 Answers2

0

Actually there is no real solution for this problem, since rails by default erases the database. It expects this database not to be shared with production (and they might have a point). Nevertheless, I found some interesting links and the way is to patch the rake task. Following the patch and links:

namespace :db do
  namespace :test do
    task :purge do
      ActiveRecord::Migration.verbose = false
      Rake::Task["db:schema:load"].invoke
    end
  end
end
Community
  • 1
  • 1
ChuckE
  • 5,610
  • 4
  • 31
  • 59
0

This is not a direct answer to your question, but you can use rspec command instead of rake spec. rspec command doesn't purge your database.

Shuhei Kagawa
  • 4,752
  • 1
  • 33
  • 31