In Ruby 5.2, we get a warning when using the "RANDOM()" function: DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "RANDOM()". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). This warning doesn't make much sense, though, since RANDOM() is a common function which is not dangerous at all. However, since the warning is annoying, we'll probably have to find a way to deal with it. So I'm extracting all our RANDOM() usages into a method. This way we'll only have to change one method to avoid this warning. I've chosen `sample` because it's similar to Ruby's Array#sample, and because `order_by_random` would be confusing if we consider we already have a method called `sort_by_random`.
17 lines
659 B
Ruby
17 lines
659 B
Ruby
section "Creating comment notifications" do
|
|
User.find_each do |user|
|
|
debate = Debate.create!(author: user,
|
|
title: Faker::Lorem.sentence(3).truncate(60),
|
|
description: "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>",
|
|
tag_list: Tag.all.sample(3).join(","),
|
|
geozone: Geozone.sample,
|
|
terms_of_service: "1")
|
|
|
|
comment = Comment.create!(user: User.sample,
|
|
body: Faker::Lorem.sentence,
|
|
commentable: debate)
|
|
|
|
Notification.add(user, comment)
|
|
end
|
|
end
|