Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Rake test to call task db:test:prepare

Every time I want to run Rake test the task db:test:prepare is being called and it rebuilds my test environment database from schema.rb and migrations. What I would like to achive is to disable the call of db:test:prepare when I want to test make Rails application. Is it possible without modifying Rails gem?

like image 602
Edvinas Bartkus Avatar asked Jul 08 '09 12:07

Edvinas Bartkus


2 Answers

Here's a solution I've seen around:

In your Rakefile:

Rake::TaskManager.class_eval do
  def remove_task(task_name)
    @tasks.delete(task_name.to_s)
  end
end

In lib/tasks/db/test.rake:

Rake.application.remove_task 'db:test:prepare'

namespace :db do
  namespace :test do 
    task :prepare do |t|
      # rewrite the task to not do anything you don't want
    end
  end
end
like image 64
mckeed Avatar answered Nov 17 '22 19:11

mckeed


There is a plugin that takes care of this for you: override_rake_task. Here is a quick usage example:

namespace :db do
  namespace :test do
    override_task :prepare do; end
  end
end
like image 38
Dave Pirotte Avatar answered Nov 17 '22 19:11

Dave Pirotte