1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove deprecated support concat errors to ActiveModel::Errors#messages

This commit is contained in:
Rafael Mendonça França 2021-11-16 00:50:35 +00:00
parent 8a5e217b47
commit 884c97fad0
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
8 changed files with 23 additions and 25 deletions

View file

@ -20,11 +20,11 @@ class ActiveModelHelperTest < ActionView::TestCase
super
@post = Post.new
assert_deprecated { @post.errors[:author_name] << "can't be empty" }
assert_deprecated { @post.errors[:body] << "foo" }
assert_deprecated { @post.errors[:category] << "must exist" }
assert_deprecated { @post.errors[:published] << "must be accepted" }
assert_deprecated { @post.errors[:updated_at] << "bar" }
@post.errors.add(:author_name, "can't be empty")
@post.errors.add(:body, "foo")
@post.errors.add(:category, "must exist")
@post.errors.add(:published, "must be accepted")
@post.errors.add(:updated_at, "bar")
@post.author_name = ""
@post.body = "Back to the hill and over it again!"

View file

@ -1341,7 +1341,7 @@ class FormOptionsHelperTest < ActionView::TestCase
def test_time_zone_select_with_priority_zones_and_errors
@firm = Firm.new("D")
@firm.extend ActiveModel::Validations
assert_deprecated { @firm.errors[:time_zone] << "invalid" }
@firm.errors.add(:time_zone, "invalid")
zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ]
html = time_zone_select("firm", "time_zone", zones)
assert_dom_equal "<div class=\"field_with_errors\">" \

View file

@ -1,3 +1,7 @@
* Remove deprecated support concat errors to `ActiveModel::Errors#messages`.
*Rafael Mendonça França*
* Remove deprecated `ActiveModel::Errors#to_xml`.
*Rafael Mendonça França*

View file

@ -542,14 +542,6 @@ module ActiveModel
super(content.freeze)
end
def <<(message)
ActiveSupport::Deprecation.warn("Calling `<<` to an ActiveModel::Errors message array in order to add an error is deprecated. Please call `ActiveModel::Errors#add` instead.")
@errors.add(@attribute, message)
__setobj__ @errors.messages_for(@attribute)
self
end
def clear
ActiveSupport::Deprecation.warn("Calling `clear` to an ActiveModel::Errors message array in order to delete all errors is deprecated. Please call `ActiveModel::Errors#delete` instead.")

View file

@ -39,7 +39,7 @@ class ErrorsTest < ActiveModel::TestCase
def test_include?
errors = ActiveModel::Errors.new(Person.new)
assert_deprecated { errors[:foo] << "omg" }
errors.add(:foo, "omg")
assert_includes errors, :foo, "errors should include :foo"
assert_includes errors, "foo", "errors should include 'foo' as :foo"
end

View file

@ -64,7 +64,7 @@ class ValidationsTest < ActiveModel::TestCase
def test_errors_on_nested_attributes_expands_name
t = Topic.new
assert_deprecated { t.errors["replies.name"] << "can't be blank" }
t.errors.add("replies.name", "can't be blank")
assert_equal ["Replies name can't be blank"], t.errors.full_messages
end

View file

@ -759,7 +759,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
def test_push_with_invalid_join_record
repair_validations(Contract) do
Contract.validate { |r| r.errors[:base] << "Invalid Contract" }
Contract.validate { |r| r.errors.add(:base, "Invalid Contract") }
firm = companies(:first_firm)
lifo = Developer.new(name: "lifo")
@ -1213,8 +1213,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
def test_create_should_not_raise_exception_when_join_record_has_errors
repair_validations(Categorization) do
Categorization.validate { |r| r.errors[:base] << "Invalid Categorization" }
assert_deprecated { Category.create(name: "Fishing", authors: [Author.first]) }
Categorization.validate { |r| r.errors.add(:base, "Invalid Categorization") }
Category.create(name: "Fishing", authors: [Author.first])
end
end
@ -1225,28 +1225,28 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
def test_create_bang_should_raise_exception_when_join_record_has_errors
repair_validations(Categorization) do
Categorization.validate { |r| r.errors[:base] << "Invalid Categorization" }
Categorization.validate { |r| r.errors.add(:base, "Invalid Categorization") }
assert_raises(ActiveRecord::RecordInvalid) do
assert_deprecated { Category.create!(name: "Fishing", authors: [Author.first]) }
Category.create!(name: "Fishing", authors: [Author.first])
end
end
end
def test_save_bang_should_raise_exception_when_join_record_has_errors
repair_validations(Categorization) do
Categorization.validate { |r| r.errors[:base] << "Invalid Categorization" }
Categorization.validate { |r| r.errors.add(:base, "Invalid Categorization") }
c = Category.new(name: "Fishing", authors: [Author.first])
assert_raises(ActiveRecord::RecordInvalid) do
assert_deprecated { c.save! }
c.save!
end
end
end
def test_save_returns_falsy_when_join_record_has_errors
repair_validations(Categorization) do
Categorization.validate { |r| r.errors[:base] << "Invalid Categorization" }
Categorization.validate { |r| r.errors.add(:base, "Invalid Categorization") }
c = Category.new(name: "Fishing", authors: [Author.first])
assert_deprecated { assert_not c.save }
assert_not c.save
end
end

View file

@ -134,6 +134,8 @@ Please refer to the [Changelog][active-model] for detailed changes.
* Remove deprecated `ActiveModel::Errors#to_xml`.
* Remove deprecated support concat errors to `ActiveModel::Errors#messages`.
### Deprecations
### Notable changes