-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deprecations on
ActiveModel::Errors
(#3869)
* Fix deprecation: ActiveModel::Errors#to_xml * Fix: Enumerating ActiveModel::Errors as a hash
- Loading branch information
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module ThreeScale | ||
module ErrorsToXml | ||
# This was deprecated with no replacement in rails 6. Because allegedly | ||
# nobody uses it. So we have to keep a copy until we completely stop | ||
# supporting XMLs in our APIs. | ||
# https://github.com/rails/rails/pull/32313 | ||
# | ||
# Returns an xml formatted representation of the Errors hash. | ||
# | ||
# person.errors.add(:name, :blank, message: "can't be blank") | ||
# person.errors.add(:name, :not_specified, message: "must be specified") | ||
# person.errors.to_xml | ||
# # => | ||
# # <?xml version=\"1.0\" encoding=\"UTF-8\"?> | ||
# # <errors> | ||
# # <error>name can't be blank</error> | ||
# # <error>name must be specified</error> | ||
# # </errors> | ||
def to_xml(options = {}) | ||
to_a.to_xml({ root: "errors", skip_types: true }.merge!(options)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.config.to_prepare do | ||
ActiveModel::Errors.prepend ThreeScale::ErrorsToXml | ||
end |