Merge pull request #3729 from consul/fix_extra_records

Fix extra records in investments and polls
This commit is contained in:
Javier Martín
2019-09-29 22:25:33 +02:00
committed by GitHub
4 changed files with 9 additions and 10 deletions

View File

@@ -42,7 +42,7 @@ class Poll < ApplicationRecord
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 :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 :recounting, -> { 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)) }
scope :public_for_api, -> { all }
@@ -86,7 +86,7 @@ class Poll < ApplicationRecord
end
def self.current_or_recounting
current + recounting
current.or(recounting)
end
def answerable_by?(user)

View File

@@ -18,7 +18,7 @@ class Valuator < ApplicationRecord
end
def assigned_investment_ids
investment_ids + [valuator_group&.investment_ids].flatten
investment_ids + valuator_group&.investment_ids.to_a
end
end

View File

@@ -119,9 +119,9 @@ describe Poll do
recounting_polls = Poll.recounting
expect(recounting_polls).to eq [recounting]
expect(recounting_polls).not_to include(current)
expect(recounting_polls).not_to include(expired)
expect(recounting_polls).to include(recounting)
end
end
@@ -133,8 +133,7 @@ describe Poll do
current_or_recounting = Poll.current_or_recounting
expect(current_or_recounting).to include(current)
expect(current_or_recounting).to include(recounting)
expect(current_or_recounting).to match_array [current, recounting]
expect(current_or_recounting).not_to include(expired)
end
end

View File

@@ -28,8 +28,8 @@ describe Valuator do
investment2.valuators << valuator
assigned_investment_ids = valuator.assigned_investment_ids
expect(assigned_investment_ids).to include investment1.id
expect(assigned_investment_ids).to include investment2.id
expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
expect(assigned_investment_ids).not_to include investment3.id
end
@@ -45,8 +45,8 @@ describe Valuator do
investment2.valuator_groups << group
assigned_investment_ids = valuator.assigned_investment_ids
expect(assigned_investment_ids).to include investment1.id
expect(assigned_investment_ids).to include investment2.id
expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
expect(assigned_investment_ids).not_to include investment3.id
end
end