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? }
|
validates_translation :description, presence: true, unless: -> { status_id.present? }
|
||||||
|
|
||||||
scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) }
|
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") }
|
scope :with_status, -> { where("status_id IS NOT NULL") }
|
||||||
|
|
||||||
def self.title_max_length
|
def self.title_max_length
|
||||||
|
|||||||
@@ -43,16 +43,17 @@ describe Milestone do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".published" do
|
describe ".published", :application_zone_west_of_system_zone do
|
||||||
it "uses the application's time zone date", :with_different_time_zone do
|
it "includes milestones published today" do
|
||||||
published_in_local_time_zone = create(:milestone,
|
todays_milestone = create(:milestone, publication_date: Time.current)
|
||||||
publication_date: Date.today)
|
|
||||||
|
|
||||||
published_in_application_time_zone = create(:milestone,
|
expect(Milestone.published).to eq [todays_milestone]
|
||||||
publication_date: Date.current)
|
end
|
||||||
|
|
||||||
expect(Milestone.published).to eq [published_in_application_time_zone]
|
it "does not include future milestones" do
|
||||||
expect(Milestone.published).not_to include(published_in_local_time_zone)
|
create(:milestone, publication_date: Date.tomorrow.beginning_of_day)
|
||||||
|
|
||||||
|
expect(Milestone.published).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ describe Poll::Officer do
|
|||||||
describe "todays_booths" do
|
describe "todays_booths" do
|
||||||
let(:officer) { create(:poll_officer) }
|
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,
|
assignment_with_local_time_zone = create(:poll_officer_assignment,
|
||||||
date: Date.today,
|
date: Date.today,
|
||||||
officer: officer)
|
officer: officer)
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ RSpec.configure do |config|
|
|||||||
travel_back
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, :with_different_time_zone) do
|
config.before(:each, :application_zone_west_of_system_zone) do
|
||||||
application_zone = ActiveSupport::TimeZone.new("UTC")
|
application_zone = ActiveSupport::TimeZone.new("Quito")
|
||||||
system_zone = ActiveSupport::TimeZone.new("Madrid")
|
system_zone = ActiveSupport::TimeZone.new("Madrid")
|
||||||
|
|
||||||
allow(Time).to receive(:zone).and_return(application_zone)
|
allow(Time).to receive(:zone).and_return(application_zone)
|
||||||
|
|||||||
Reference in New Issue
Block a user