Ash FrameworkAF
Ash Framework5mo ago
6 replies
theopechli

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,
           # 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
The starter application for the Ash Framework book - sevenseacat/tunez
tunez/lib/tunez/music/album.ex at 81078dc05cf42fa80945c33b6f90debab...
Solution
huh. you're right! the message is slightly incorrect - but the code reflects my intention
Was this page helpful?