Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Don't allow album release date to be in the future #141

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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