Skip to content

Commit

Permalink
Ensure Time.zone.today is evaluated at comparison time
Browse files Browse the repository at this point in the history
Before this commit I think `Time.zone.today` was only being evaluated
when the application first booted, rather than each time the
validation was called. This manifested as validation error messages
for some users when the application hadn't been deployed for several
days (e.g. #169).

I'm hopeful that passing a lambda to `less_than_or_equal_to` will fix
this but I'm unsure of how to express that in a test.
  • Loading branch information
chrislo committed Feb 13, 2024
1 parent 6bb1e3d commit 12e0e22
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/album.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Album < ApplicationRecord

validates :title, presence: true
validates :price, presence: true, numericality: true
validates :released_on, comparison: { less_than_or_equal_to: Time.zone.today, allow_blank: true }
validates :released_on, comparison: { less_than_or_equal_to: -> { Time.zone.today }, allow_blank: true }
validates :number_of_tracks, comparison: { greater_than: 0 }, if: :published?
validates(
:cover,
Expand Down

1 comment on commit 12e0e22

@floehopper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh - sorry! 💩

Please sign in to comment.