toptal / database_validations

Database validations for ActiveRecord
MIT License
538 stars 13 forks source link

Relax AR version, add test for different version #36

Closed palkan closed 5 years ago

palkan commented 5 years ago

Thanks for the gem!

I'm using it with Rails 6 – it works) So, let's relax the constraints.

Added travis configuration to run tests against different versions (to make sure that it really works).

palkan commented 5 years ago

AR 3.2 is not supported by this gem: https://travis-ci.org/toptal/database_validations/jobs/496140442

Ruby <2.5 is not supported, too: https://travis-ci.org/toptal/database_validations/jobs/496143426 (so this one, probably, should be easy to fix).

pirj commented 5 years ago

Except probably the gem is only compatible with AR 4.2+.

palkan commented 5 years ago

Except probably the gem is only compatible with AR 4.2+.

Yeah, it should be. I'm trying to make specs work)

palkan commented 5 years ago

@pirj What about Ruby 2.4? We can try to make it work, too

palkan commented 5 years ago

the gem is only compatible with AR 4.2+.

It's not( https://travis-ci.org/toptal/database_validations/jobs/496152914

pirj commented 5 years ago

@palkan Definitely, I believe something like klass.__send__(:alias_method will fix the issue.

As per this writeup, which is only a bit over one year old, about a third of installations use Rubies that don't receive security updates anymore. Keeping in mind that 2.3 will fall into this category by April, it doesn't make much sense to support versions prior to 2.4.

pirj commented 5 years ago

the gem is only compatible with AR 4.2+.

It's not

You're right! Unknown key: :optional should be relatively easy to fix as well by picking either options.merge(optional: true) or options.merge(required: false) depending on AR version.

undefined method 'details' for #<ActiveModel::Errors might be more tricky. Let's probably leave it up for @djezzzl to add support for 4.2?

palkan commented 5 years ago

Finally, we're green)

Not supported by Rails 4 features are excluded from specs (using RAILS_5 constant and a few changes).

Differences in belongs_to are handled in code (optional vs required and error messages).

Let's try to make it work on Ruby 2.4

palkan commented 5 years ago

Ok, Ruby 2.4 is fixed, too

djezzzl commented 5 years ago

Thank you for your contribution!

pirj commented 5 years ago

👏