Faveod / arel-extensions

Extending Arel
MIT License
142 stars 24 forks source link

Fix .floor calculations for SQLite #18

Closed f3ndot closed 4 years ago

f3ndot commented 4 years ago

The SQLite visitor is bugged under the following conditions:

  1. when x = 10, x.floor is expected to be 10 but is 9
  2. when x = 10.01, x.floor is expected to be 10 but is 9
  3. when x = 0, x.floor is expected to be 0 but is -1
  4. when x = -10.99, x.floor is expected to be -11 but is -12

Reimplementing the visitor to use CASE + CAST satisfies these conditions and fixes the floor implementation.