From 211398bd9d63c82150e492d6762dc6389601bc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 10 Oct 2019 01:55:21 +0200 Subject: [PATCH 1/3] Use a more expressive name for time zone tests "With different time zone" didn't clarify which time zone was different nor what it was different to. --- spec/models/milestone_spec.rb | 2 +- spec/models/poll/officer_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 4ad6fcd6e..4904a1ab1 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -44,7 +44,7 @@ describe Milestone do end describe ".published" do - it "uses the application's time zone date", :with_different_time_zone do + it "uses the application's time zone date", :application_zone_west_of_system_zone do published_in_local_time_zone = create(:milestone, publication_date: Date.today) diff --git a/spec/models/poll/officer_spec.rb b/spec/models/poll/officer_spec.rb index 199bf487f..8c9e9525c 100644 --- a/spec/models/poll/officer_spec.rb +++ b/spec/models/poll/officer_spec.rb @@ -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) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 18b996d38..57172b71f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -109,7 +109,7 @@ RSpec.configure do |config| travel_back 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") system_zone = ActiveSupport::TimeZone.new("Madrid") From 0f2a96979ef11af2530bc1f946fe8663abee316b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 10 Oct 2019 01:59:06 +0200 Subject: [PATCH 2/3] Don't use UTC as application zone in time zone tests It was a bit confusing, since Travis uses UTC as the system zone, while most application zones are not UTC. --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 57172b71f..ad465ecc5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -110,7 +110,7 @@ RSpec.configure do |config| end 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") allow(Time).to receive(:zone).and_return(application_zone) From 6a6a8bf365316a7e9c32f59f6566f74d2aacf2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 10 Oct 2019 02:21:34 +0200 Subject: [PATCH 3/3] Fix milestone publication date comparison We're storing the publication date as datetime in the database, and we were comparing it to a date, meaning today's milestones were not being found. --- app/models/milestone.rb | 2 +- spec/models/milestone_spec.rb | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/milestone.rb b/app/models/milestone.rb index d4219c004..f36120fa1 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -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 diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 4904a1ab1..e24c43314 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -43,16 +43,17 @@ describe Milestone do end end - describe ".published" do - it "uses the application's time zone date", :application_zone_west_of_system_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