Remove duplicate scope

The scopes `created_by_admin` and `public_polls` were very similar. I'm
using `created_by_admin` because `Poll.public_polls` feels redundant,
and the reason for that name is we should not name the scope `public`
because `public` is a ruby access modifier.
This commit is contained in:
Javi Martín
2019-11-08 21:11:25 +01:00
parent 864f750d92
commit 9e27027f56
2 changed files with 1 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ class PollsController < ApplicationController
def index def index
@polls = Kaminari.paginate_array( @polls = Kaminari.paginate_array(
@polls.public_polls.not_budget.send(@current_filter).includes(:geozones).sort_for_list @polls.created_by_admin.not_budget.send(@current_filter).includes(:geozones).sort_for_list
).page(params[:page]) ).page(params[:page])
end end

View File

@@ -40,7 +40,6 @@ class Poll < ApplicationRecord
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
scope :for, ->(element) { where(related: element) } scope :for, ->(element) { where(related: element) }
scope :public_polls, -> { where(related: nil) }
scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) } scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) }
scope :expired, -> { where("ends_at < ?", 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 :recounting, -> { where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) }