Make poll scope more readable

This was the only place where we used the `? <= field` format; we use
the `field >= ?` format everywhere else.

We're also adding a variable to make it easier to understand that the
value is the same in both cases and to make the line shorter ;).
This commit is contained in:
Javi Martín
2022-09-07 20:06:05 +02:00
parent 3543767951
commit f5a524d503

View File

@@ -42,7 +42,7 @@ class Poll < ApplicationRecord
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
scope :for, ->(element) { where(related: element) }
scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) }
scope :current, -> { where("starts_at <= :time and ends_at >= :time", time: Date.current.beginning_of_day) }
scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) }
scope :recounting, -> { where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)...Date.current.beginning_of_day) }
scope :published, -> { where(published: true) }