Add recounting Poll scope with trait and spec
This commit is contained in:
@@ -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)) }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user