Filling the database with test data using Populator and Faker
Often there is a need to test the application for working with real data. Moreover, the data should be as close as possible to the real both from the qualitative side and from the quantitative one. The work on filling the database with such data is greatly simplified by the Populator and Faker gems. Suppose we have a User model:
email: string
first_name: string
last_name: string
ssn: string
security_question: string
answer: string
phone: string
address: string
city: string
state: string
zip: string
To generate 1000 test users for the users table, we will use the following code:
It should be noted that Populator does not inherit the ActiveRecord model, but works directly from the database in order to improve performance. Array or Range can be passed as field value, Populator will automatically select random. ')