Skip to content

Commit

Permalink
WIP: Don't allow album release date to be in the future
Browse files Browse the repository at this point in the history
TODO: We need to decide what to do about the 2 existing albums that this
would render invalid.
  • Loading branch information
floehopper committed Jan 9, 2024
1 parent 030daa8 commit 66f9219
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/album.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 }

belongs_to :artist
has_many :tracks, -> { order(position: :asc) }, dependent: :destroy, inverse_of: :album
Expand Down
8 changes: 8 additions & 0 deletions test/models/album_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,12 @@ class AlbumTest < ActiveSupport::TestCase
assert_not album.valid?
assert_includes album.errors[:cover], 'must be an image file (jpeg, png)'
end

test 'is not valid if released_on is a date in the future' do
freeze_time do
album = build(:album, released_on: 1.day.from_now)
assert_not album.valid?
assert_includes album.errors[:released_on], "must be less than or equal to #{Time.zone.today}"
end
end
end

0 comments on commit 66f9219

Please sign in to comment.