Closed plicjo closed 8 years ago
@plicjo Great job with the pull request. I've also started working on adapting schema_validations, but you obviously beat me to it. :)
I'm now reviewing it, but as far as tests and coverage go it looks ready.
Besides that, the main issue I see right now, is that the detected types don't necessarily match the ActiveModel types mapped to the database. Changes in Rails 5 mean we cannot call #number?
on types, and we don't get the casted type directly so we could call #number?
or #range?
on.
In the second case, I haven't seen any example of rails using anything besides an integer range, so that might be just fine. With numeric types things are more complicated, since Postgres has the Money type, for instance, and it looks like it won't be detected as numeric. Then again, the old code might have been wrong too, since it detected Money as numeric, but not as decimal.
I have a workaround ready from my own attempts that allows us to check for #numeric?
in a compatible way, but I'm not sure if it actually solves the issue. Perhaps we should just add explicit mappings for types like :money
instead.
@ronen Thoughts?
@boazy Thank you! If you give me a list of the missing, unsupported types, I can take care of it.
I took a look at the Rails source code, and I also came to the conclusion that the #range check appears to only be concerned with integers.
With the current version of Rails it seems that the only missing type is :money from PostgreSQL which should be mapped to Decimal. I'm more concerned about future types but this particular part of Rails seems prone to breaking changes no matter which implementation we choose.
Thanks @plicjo for taking this on! And thanks @boazy for looking into it.
I'd say if the tests pass, we're OK to release. Support for other types and whatnot can always be added in future releases. Do you agree?
I agree, if we convert money to decimal of course. That alone is a regression, although the currwnt behavior ia not fully correct either. This is jus one line.
Yeah, certainly may as well fix that. Since the current behavior for money is broken, instead of considering it a regression, should we consider it to be a bug fix? And so this would be a patch release rather than major?
Let's merge and then apply the bugfix then.
I opened an issue for adding support for the Postgres :money column type. https://github.com/SchemaPlus/schema_validations/issues/45
Thanks @plicjo. I've merged your pull request and I'll try to fix that issue today.
@ronen Can you please release a new version?
Sorry, I got confused and thought I was waiting for another fix from you. Just realized now it's all set (when #47 came in).
Released 2.2.0
Thanks @ronen! I'll test the new schema_validations today in a live project ;) Doy we have any major modules left without Rails 5 support now besides schema_plus_views?
This PR has all of the schema_validations tests passing for Rails 5 and Rails 4.2.
Cheers!