mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated ActiveModel::Errors#to_xml
This commit is contained in:
parent
edc4e7dfb5
commit
73872c7220
4 changed files with 7 additions and 31 deletions
|
@ -1,3 +1,7 @@
|
|||
* Remove deprecated `ActiveModel::Errors#to_xml`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `ActiveModel::Errors#keys`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
|
|
@ -208,22 +208,6 @@ module ActiveModel
|
|||
@errors.map(&:attribute).uniq.freeze
|
||||
end
|
||||
|
||||
# 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 = {})
|
||||
deprecation_removal_warning(:to_xml)
|
||||
to_a.to_xml({ root: "errors", skip_types: true }.merge!(options))
|
||||
end
|
||||
|
||||
# Returns a Hash that can be used as the JSON representation for this
|
||||
# object. You can pass the <tt>:full_messages</tt> option. This determines
|
||||
# if the json object should contain full messages or not (false by default).
|
||||
|
@ -511,15 +495,6 @@ module ActiveModel
|
|||
}
|
||||
end
|
||||
|
||||
def deprecation_removal_warning(method_name, alternative_message = nil)
|
||||
message = +"ActiveModel::Errors##{method_name} is deprecated and will be removed in Rails 7.0."
|
||||
if alternative_message
|
||||
message << "\n\nTo achieve the same use:\n\n "
|
||||
message << alternative_message
|
||||
end
|
||||
ActiveSupport::Deprecation.warn(message)
|
||||
end
|
||||
|
||||
def deprecation_rename_warning(old_method_name, new_method_name)
|
||||
ActiveSupport::Deprecation.warn("ActiveModel::Errors##{old_method_name} is deprecated. Please call ##{new_method_name} instead.")
|
||||
end
|
||||
|
|
|
@ -207,16 +207,11 @@ class ValidationsTest < ActiveModel::TestCase
|
|||
assert_equal [:b, :a], t.call_sequence
|
||||
end
|
||||
|
||||
def test_errors_conversions
|
||||
def test_errors_to_json
|
||||
Topic.validates_presence_of %w(title content)
|
||||
t = Topic.new
|
||||
assert_predicate t, :invalid?
|
||||
|
||||
xml = assert_deprecated { t.errors.to_xml }
|
||||
assert_match %r{<errors>}, xml
|
||||
assert_match %r{<error>Title can't be blank</error>}, xml
|
||||
assert_match %r{<error>Content can't be blank</error>}, xml
|
||||
|
||||
hash = {}
|
||||
hash[:title] = ["can't be blank"]
|
||||
hash[:content] = ["can't be blank"]
|
||||
|
|
|
@ -132,6 +132,8 @@ Please refer to the [Changelog][active-model] for detailed changes.
|
|||
|
||||
* Remove deprecated `ActiveModel::Errors#keys`.
|
||||
|
||||
* Remove deprecated `ActiveModel::Errors#to_xml`.
|
||||
|
||||
### Deprecations
|
||||
|
||||
### Notable changes
|
||||
|
|
Loading…
Reference in a new issue