Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep data when run test in rails

Every time I run test. Rails will delete my data from table. I have million of record in my table for testing search performance and corrective. I can't add data every time I run test.

How to tell rails "Please don't delete data in this table" when i run test.

ps.

I found this link

How do I run Rails integration tests without dropping DB contents?

It's maybe relate to my problems but I don't know where to put his code in my rails project.

like image 780
Bank Avatar asked Dec 23 '22 10:12

Bank


1 Answers

Very similar to neokain's previous post, however, his didn't work on Rails 3 for me. I went ahead and dropped this into my Rakefile at the root of the app and when I run test:units, it doesn't blow away all of my existing tables:

Rake::TaskManager.class_eval do
  def delete_task(task_name)
    @tasks.delete(task_name.to_s)
  end
  Rake.application.delete_task("db:test:purge")
  Rake.application.delete_task("db:test:prepare")
end

namespace :db do
  namespace :test do
    task :purge do
    end
    task :prepare do
    end
  end
end
like image 103
Joe Goggins Avatar answered Jan 08 '23 05:01

Joe Goggins