NHSDigital / activemodel-caution

ActiveModel non-blocking warning gem
MIT License
2 stars 1 forks source link

Support Rails 6.1-style errors #3

Open joshpencheon opened 3 years ago

joshpencheon commented 3 years ago

Rails 6.1 has changed how errors are structured internally, which will affect how activemodel-caution should function.

See the new API docs.

# On the rails/rails repo:
$ git diff v6.0.3.5..v6.1.2.1 --stat -- {activemodel/lib/active_model,activerecord/lib/active_record}/{error,validat}*
 activemodel/lib/active_model/error.rb                      | 207 +++++++++++++++
 activemodel/lib/active_model/errors.rb                     | 524 +++++++++++++++++++++++---------------
 activemodel/lib/active_model/validations.rb                |  12 +-
 activemodel/lib/active_model/validations/absence.rb        |   2 +-
 activemodel/lib/active_model/validations/acceptance.rb     |   2 +-
 activemodel/lib/active_model/validations/callbacks.rb      |  30 +--
 activemodel/lib/active_model/validations/clusivity.rb      |   6 +-
 activemodel/lib/active_model/validations/confirmation.rb   |   4 +-
 activemodel/lib/active_model/validations/exclusion.rb      |   2 +-
 activemodel/lib/active_model/validations/format.rb         |   4 +-
 activemodel/lib/active_model/validations/inclusion.rb      |   2 +-
 activemodel/lib/active_model/validations/length.rb         |   4 +-
 activemodel/lib/active_model/validations/numericality.rb   |  95 ++++---
 activemodel/lib/active_model/validations/presence.rb       |   2 +-
 activemodel/lib/active_model/validations/validates.rb      |  10 +-
 activemodel/lib/active_model/validator.rb                  |   8 +-
 activerecord/lib/active_record/errors.rb                   |  59 ++++-
 activerecord/lib/active_record/validations.rb              |   1 +
 activerecord/lib/active_record/validations/numericality.rb |  35 +++
 activerecord/lib/active_record/validations/uniqueness.rb   |  28 +-
 20 files changed, 734 insertions(+), 303 deletions(-)

We'll likely need to swap activemodel-caution over to the new structure, as well as mirror the deprecations.

Frustratingly, we've still got a number of use cases for the "active" warnings... regardless, I wonder if it might not be possible to change how this gem functions - to give objects a proxy "warning object" that uses ActiveModel::Error, meaning we'd not be duplicating the entire library.

joshpencheon commented 3 years ago

cc: @miles-smith , something to mull on!