Add recounting Poll scope with trait and spec

This commit is contained in:
Bertocq
2017-10-13 16:48:25 +02:00
parent 540e12a3ac
commit ca2d9a1d68
3 changed files with 22 additions and 0 deletions

View File

@@ -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)) }

View File

@@ -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

View File

@@ -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) }