kala-tamin How to keep data when run test in rails


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

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.




Rails App fails at startup?

1:



Rails: using ZenTest / autospec to test specs in new directories
Very similar to neokain's previous post, however, his didn't work on Rails 3 for me.


How to build good documentation with REST API in Rails?
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:.
Partial with Multiple Variables
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 


ActiveRecord: Cache and automatically update (redundant) attributes - Best Practice


Capistrano's Failure

2:



Lifestream in Rails
In Rails 4 I end up with following.
Attachment_fu failing to validate on update
# lib/tasts/test.rake # Do not drop database for tests if ENV['RAILS_ENV'] == 'test'   Rake::TaskManager.class_eval do     def delete_task(task_name)       @tasks.delete(task_name.to_s)     end   end    Rake.application.delete_task("db:test:load")    namespace :db do     namespace :test do       task :load do       end     end   end end 


3:


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..


4:


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..



99 out of 100 based on 89 user ratings 789 reviews