Merge pull request #3760 from consul/fix_milestone_published

Fix milestone publication date comparison
This commit is contained in:
Javier Martín
2019-10-10 20:58:22 +02:00
committed by GitHub
4 changed files with 13 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ class Milestone < ApplicationRecord
validates_translation :description, presence: true, unless: -> { status_id.present? }
scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) }
scope :published, -> { where("publication_date <= ?", Date.current) }
scope :published, -> { where("publication_date <= ?", Date.current.end_of_day) }
scope :with_status, -> { where("status_id IS NOT NULL") }
def self.title_max_length

View File

@@ -43,16 +43,17 @@ describe Milestone do
end
end
describe ".published" do
it "uses the application's time zone date", :with_different_time_zone do
published_in_local_time_zone = create(:milestone,
publication_date: Date.today)
describe ".published", :application_zone_west_of_system_zone do
it "includes milestones published today" do
todays_milestone = create(:milestone, publication_date: Time.current)
published_in_application_time_zone = create(:milestone,
publication_date: Date.current)
expect(Milestone.published).to eq [todays_milestone]
end
expect(Milestone.published).to eq [published_in_application_time_zone]
expect(Milestone.published).not_to include(published_in_local_time_zone)
it "does not include future milestones" do
create(:milestone, publication_date: Date.tomorrow.beginning_of_day)
expect(Milestone.published).to be_empty
end
end
end

View File

@@ -127,7 +127,7 @@ describe Poll::Officer do
describe "todays_booths" do
let(:officer) { create(:poll_officer) }
it "returns booths for the application's time zone date", :with_different_time_zone do
it "returns booths for the application's time zone date", :application_zone_west_of_system_zone do
assignment_with_local_time_zone = create(:poll_officer_assignment,
date: Date.today,
officer: officer)

View File

@@ -109,8 +109,8 @@ RSpec.configure do |config|
travel_back
end
config.before(:each, :with_different_time_zone) do
application_zone = ActiveSupport::TimeZone.new("UTC")
config.before(:each, :application_zone_west_of_system_zone) do
application_zone = ActiveSupport::TimeZone.new("Quito")
system_zone = ActiveSupport::TimeZone.new("Madrid")
allow(Time).to receive(:zone).and_return(application_zone)