Merge pull request #3760 from consul/fix_milestone_published
Fix milestone publication date comparison
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user