diff --git a/app/models/poll.rb b/app/models/poll.rb index c572a4765..41d4a9ab9 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -25,6 +25,7 @@ class Poll < ActiveRecord::Base scope :current, -> { where('starts_at <= ? and ? <= ends_at', Date.current.beginning_of_day, Date.current.beginning_of_day) } scope :incoming, -> { where('? < starts_at', Date.current.beginning_of_day) } scope :expired, -> { where('ends_at < ?', Date.current.beginning_of_day) } + scope :recounting, -> { Poll.where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) } scope :published, -> { where('published = ?', true) } scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) } diff --git a/spec/factories.rb b/spec/factories.rb index 69aa92c62..b1c5ff329 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -489,6 +489,11 @@ FactoryGirl.define do ends_at { 15.days.ago } end + trait :recounting do + starts_at { 1.month.ago } + ends_at { Date.current } + end + trait :published do published true end diff --git a/spec/models/poll/poll_spec.rb b/spec/models/poll/poll_spec.rb index 5083d7439..dba964928 100644 --- a/spec/models/poll/poll_spec.rb +++ b/spec/models/poll/poll_spec.rb @@ -76,6 +76,22 @@ describe :poll do end end + describe "#recounting" do + it "returns polls in recount & scrutiny phase" do + current = create(:poll, :current) + incoming = create(:poll, :incoming) + expired = create(:poll, :expired) + recounting = create(:poll, :recounting) + + recounting_polls = Poll.recounting + + expect(recounting_polls).to_not include(current) + expect(recounting_polls).to_not include(incoming) + expect(recounting_polls).to_not include(expired) + expect(recounting_polls).to include(recounting) + end + end + describe "answerable_by" do let(:geozone) {create(:geozone) }