dm-validations stringy regexp validations fail scientific notation
I have a couple Float values in my database. The validations in dm-validations kept giving me validations from time to time. I tracked it down to the regexps in dm-validations.
The to_s here (line 20) will sometimes be in scientific notation. For example -0.00004 (-4.0e-05) so all the regexp validations futher down (~line 45 onwards) fail.
The two fixes I can think of are converting everything to BigDecimal and using .to_s('F') or adding an exponent alternative to each regexp. I'm happy to submit a patch for either (or if you have a better idea).
Comments and changes to this ticket
- State changed from new to confirmed
I would say use the approach that will result in the least amount of complex code. Adding an extra regexp to each of those seems like it would result in alot more code than using BigDecimal#to_s like you said. If you would like to submit a patch for this I would gladly accept it.
Merged scientific-notation-fix branch into next as well since I don't know how you guys expect patches to be submitted. I hope that's ok.
- State changed from accepted to resolved
(from [0c58330f1ee3b27978fec1e3331c1b68417a738a]) [dm-validations] Avoid scientific notation in Float.to_s
- This allows precision and scale regexps to work in case the float value is represented in scientific notation internally.