Problem
I'm currently using Selenium for full-stack testing. Right now I'm using factory girl to populate my database, which, as the application grows, is a bit tidies. Is there a way to create a small copy of the production database with minimal effort? I don't want the entire db in my test suit as it's over 10GB. But instead only a few records of each model.
I can write a script by hand that does this, but I was hoping that a gem or similar already exists that does this for me.
How would it work?
I as a tester defines the minimum amount of records for each model. The associations for each model is also copied.
Here's an example
class User < ActiveRecord::Base
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :user
belongs_to :question
end
class Question < ActiveRecord::Base
has_many :options
end
class Option < ActiveRecord::Base
belongs_to :question
end
Example configuration of how the script might look like
{
User: 5,
Option: 1
}
This would copy 5 users with all of its associations, except for the Option model which we only includes one of.
Environment
- Postgresql
- Rails 4
Notes
Please note that my application consists of over 400 models with complex relations. Manually trying to keep the testing database in sync with the production database using fixtures/factories (for these type of tests) would be a hazel.
Also note that I'm using fixtures for unit testing, which works very well, but in this case I need a prepopulated database for the higher level tests.
Aucun commentaire:
Enregistrer un commentaire