0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Railsでupdated_atがばらばらなテストデータを作りたい

0
Last updated at Posted at 2023-02-02

備忘録

結論

gem fakerを利用するぅ

group :development, :test do
   gem 'faker'
end

今回は既存データをアップデートしてます。

models.each do |hoge|
    fake_date = Faker::Date.between(from: 100.days.ago, to: Date.today)
    hoge.update(Model.touch_attributes_with_time(*[], time: fake_date))
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?