views:

82

answers:

2

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

http://stackoverflow.com/questions/433724/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.

+1  A: 

The "rake test" task always runs db:test:prepare which will recreate your database.

You can add this somewhere in lib/tasks:

if ENV['NO_DB']
  namespace :db do
    namespace :test do
      task :prepare do
      end
    end
  end
end

And then run NO_DB=1 rake test. Also when you use autotest instead of the rake tasks the DB won't be changed.

mutle
+1  A: 

I try to do allow first answer but not work.

I search and found this www.pervasivecode.com and I modify code from first answer like this:

if ENV['NO_DB']
  Rake::TaskManager.class_eval do
    def delete_task(task_name)
      @tasks.delete(task_name.to_s)
    end
    Rake.application.delete_task("db:test:purge")
  end

  namespace :db do
   namespace :test do
    task :prepare do
    end
   end
  end
end

Then run command test allow first answer. Database test is not drop.

neokain