aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-26 11:57:43 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-26 12:01:13 +0200
commit7bd85a8fc2d216a5e2b1d0380df572f782a54d1c (patch)
tree0e9a1b63353b01244bce81bb7262bfb87e92b997 /activemodel/test/cases/validations_test.rb
parentcfaaed3f40e820d2b4d60c2d8bc1f9a005cee086 (diff)
downloadrails-7bd85a8fc2d216a5e2b1d0380df572f782a54d1c.tar.gz
rails-7bd85a8fc2d216a5e2b1d0380df572f782a54d1c.tar.bz2
rails-7bd85a8fc2d216a5e2b1d0380df572f782a54d1c.zip
Work around the fact the JSON gem was overwriting to_json implementation for all Ruby core classes.
This is required because the JSON gem is incompatible with Rails behavior and was not allowing ActiveModel::Errors to be serialized. So we need to ensure Rails implementation is the one triggered. [#4890 state:resolved]
Diffstat (limited to 'activemodel/test/cases/validations_test.rb')
-rw-r--r--activemodel/test/cases/validations_test.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb
index 228c1c074f..e94d8ce88c 100644
--- a/activemodel/test/cases/validations_test.rb
+++ b/activemodel/test/cases/validations_test.rb
@@ -6,6 +6,9 @@ require 'models/reply'
require 'models/custom_reader'
require 'models/automobile'
+require 'active_support/json'
+require 'active_support/xml_mini'
+
class ValidationsTest < ActiveModel::TestCase
def setup
@@ -158,12 +161,18 @@ class ValidationsTest < ActiveModel::TestCase
end
end
- def test_errors_to_xml
- r = Reply.new :title => "Wrong Create"
- assert r.invalid?
- xml = r.errors.to_xml(:skip_instruct => true)
- assert_equal "<errors>", xml.first(8)
- assert xml.include?("<error>Content is Empty</error>")
+ def test_errors_conversions
+ Topic.validates_presence_of %w(title content)
+ t = Topic.new
+ assert t.invalid?
+
+ xml = 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
+
+ json = t.errors.to_json
+ assert_equal t.errors.to_a.to_json, json
end
def test_validation_order