Test data generation using Rails Faker

Asked 1 years ago, Updated 1 years ago, 94 views

I'm developing it at Ruby on Rails.
I use Fakergem to put test data in DB(mysql).
https://github.com/stympy/faker I was able to put in most of the data, but there are some things that I can't do with this.

Please tell me how I can resolve the above issues!

ruby-on-rails mysql rubygems

2022-09-30 19:45

1 Answers

If I were to make test data, it would be like this.
(I don't know what kind of code Kim is writing, so I'm writing it in my imagination.)

 schedule=Schedule.new

# 1. True/false settings do not use Faker
schedule.repeat=true#false can also be used

# 2. String only hours, minutes, and seconds from random date (e.g., "07:31:51")
schedule.scheduled_time=Faker::Time.between(DateTime.now-1, DateTime.now).strftime("%H:%M:%S")

# 3. Randomly set large or small
schedule.room=%w(large small).sample

schedule.save!

If it's a case like the question, I don't think I need to force myself to use Faker.


2022-09-30 19:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.