Possibly wrong `numericality` validation in `tunez` repo

Hello, I know this is a bit silly but considering that it's being accompanied by a book I thought I'd let you know that, unless I am misunderstanding something, in the Album Resource the year_released validation is slightly off. https://github.com/sevenseacat/tunez/blob/81078dc05cf42fa80945c33b6f90debab76700b2/lib/tunez/music/album.ex#L75-L80 The year must be in the range (1950, next_year), whereas currently it validates it to be in the range (1950, next_year].
validate numericality(:year_released,
greater_than: 1950,
# Bad
less_than_or_equal_to: &__MODULE__.next_year/0
),
where: [present(:year_released)],
message: "must be between 1950 and next year"
validate numericality(:year_released,
greater_than: 1950,
# Bad
less_than_or_equal_to: &__MODULE__.next_year/0
),
where: [present(:year_released)],
message: "must be between 1950 and next year"
->
validate numericality(:year_released,
greater_than: 1950,
# Good
less_than: &__MODULE__.next_year/0
),
where: [present(:year_released)],
message: "must be between 1950 and next year"
validate numericality(:year_released,
greater_than: 1950,
# Good
less_than: &__MODULE__.next_year/0
),
where: [present(:year_released)],
message: "must be between 1950 and next year"
Also, I didn't know where to post this and didn't want to spam the general channel, so if this is the wrong place... oops.
GitHub
tunez/lib/tunez/music/album.ex at 81078dc05cf42fa80945c33b6f90debab...
The starter application for the Ash Framework book - sevenseacat/tunez
Solution:
huh. you're right! the message is slightly incorrect - but the code reflects my intention
Jump to solution
4 Replies
Solution
sevenseacat
sevenseacat•2mo ago
huh. you're right! the message is slightly incorrect - but the code reflects my intention
theopechli
theopechliOP•2mo ago
ohh ok got it!
sevenseacat
sevenseacat•2mo ago
unfortunately it's a bit late to change it in the book 😅 but I hope that little issue doesn't detract from your understanding, given you've spotted that oops!
theopechli
theopechliOP•2mo ago
yea, no worries!

Did you find this page helpful?