aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorlulalala <mark@goodlife.tw>2018-04-03 00:17:45 +0800
committerlulalala <mark@goodlife.tw>2019-03-31 22:59:12 +0800
commitcccbac6df6de18b98e300fdd973758447446dbee (patch)
tree4b5565486d67716e68c20af2b12550f83c3e93fc /activemodel
parent86b4aa1175b23deca15981fbc19cf7f02b13b25d (diff)
downloadrails-cccbac6df6de18b98e300fdd973758447446dbee.tar.gz
rails-cccbac6df6de18b98e300fdd973758447446dbee.tar.bz2
rails-cccbac6df6de18b98e300fdd973758447446dbee.zip
Add a transitional method `objects`, for accessing the array directly.
This is because we try to accommodate old hash behavior, so `first` and `last` now does not return Error object.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/errors.rb1
-rw-r--r--activemodel/test/cases/errors_test.rb12
2 files changed, 7 insertions, 6 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 98e16ea455..805d042cac 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -74,6 +74,7 @@ module ActiveModel
self.i18n_customize_full_message = false
attr_reader :errors
+ alias :objects :errors
# Pass in the instance of the object that is using the errors object.
#
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 58aa7ee147..048b8a92fb 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -159,14 +159,14 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal :name, error.attribute
assert_equal :blank, error.type
- assert_equal error, person.errors.first
+ assert_equal error, person.errors.objects.first
end
test "add, with type as symbol" do
person = Person.new
person.errors.add(:name, :blank)
- assert_equal :blank, person.errors.first.type
+ assert_equal :blank, person.errors.objects.first.type
assert_equal ["can't be blank"], person.errors[:name]
end
@@ -183,7 +183,7 @@ class ErrorsTest < ActiveModel::TestCase
person = Person.new
person.errors.add(:name)
- assert_equal :invalid, person.errors.first.type
+ assert_equal :invalid, person.errors.objects.first.type
assert_equal ["is invalid"], person.errors[:name]
end
@@ -203,7 +203,7 @@ class ErrorsTest < ActiveModel::TestCase
person = Person.new
person.errors.add(:name, type)
- assert_equal :blank, person.errors.first.type
+ assert_equal :blank, person.errors.objects.first.type
assert_equal ["can't be blank"], person.errors[:name]
end
@@ -214,7 +214,7 @@ class ErrorsTest < ActiveModel::TestCase
person = Person.new
person.errors.add(:name, :blank, message: type)
- assert_equal :blank, person.errors.first.type
+ assert_equal :blank, person.errors.objects.first.type
assert_equal [msg], person.errors[:name]
end
@@ -225,7 +225,7 @@ class ErrorsTest < ActiveModel::TestCase
person = Person.new
person.errors.add(:name, message: type)
- assert_equal :invalid, person.errors.first.type
+ assert_equal :invalid, person.errors.objects.first.type
assert_equal [msg], person.errors[:name]
end