提交 1ec126dd 编写于 作者: J José Valim

Revert "Fix generation of wrong json string when field has multiple errors"

This reverts commit a9b666b5.
上级 ba63c0a9
......@@ -168,16 +168,6 @@ def as_json(options=nil)
self
end
def encode_json(encoder)
errors = []
each_pair do |key, value|
value = value.first if value.size == 1
errors << "#{encoder.encode(key.to_s)}:#{encoder.encode(value, false)}"
end
"{#{errors * ','}}"
end
# Adds +message+ to the error messages on +attribute+, which will be returned on a call to
# <tt>on(attribute)</tt> for the same attribute. More than one error can be added to the same
# +attribute+ in which case an array will be returned on a call to <tt>on(attribute)</tt>.
......
......@@ -62,14 +62,4 @@ def self.lookup_ancestors
end
test 'to_json should return valid json string' do
person = Person.new
person.errors.add(:name, "can not be blank")
person.errors.add(:name, "can not be nil")
hash = ActiveSupport::OrderedHash[:name, ["can not be blank", "can not be nil"]]
assert_equal person.errors.to_json, hash.to_json
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册