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.
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", :application_zone_west_of_system_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
|
||||||
|
|||||||
Reference in New Issue
Block a user