Fix rails db:seed error (#11272)

rails db:seed sometimes tries to create two 'vomit'
reactions on the same Article which is prohibited by the
validations on the Reaction model.
This commit is contained in:
Alexandre Ruban 2020-11-04 17:55:05 +01:00 committed by GitHub
parent 474ba1688f
commit ad747a271f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -450,9 +450,16 @@ seeder.create_if_none(FeedbackMessage) do
)
3.times do
article_id = Article
.left_joins(:reactions)
.where.not(articles: { id: Reaction.article_vomits.pluck(:reactable_id) })
.order(Arel.sql("RANDOM()"))
.first
.id
Reaction.create!(
category: "vomit",
reactable_id: Article.order(Arel.sql("RANDOM()")).first.id,
reactable_id: article_id,
reactable_type: "Article",
user_id: mod.id,
)