From c5ee7923bb6d38f138e58e7da5f9dfaa85bb9721 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Oct 2012 13:49:04 -0500 Subject: allow serializing the error objects as json --- t/json.t | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 t/json.t (limited to 't/json.t') diff --git a/t/json.t b/t/json.t new file mode 100644 index 0000000..a2abf93 --- /dev/null +++ b/t/json.t @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Test::Requires 'JSON'; + +use Moose::Util::TypeConstraints 'find_type_constraint'; + +use MooseX::Validation::Doctypes; + +doctype 'Person' => { + id => 'Str', + name => 'Str', + title => 'Str', +}; + +my $JSON = JSON->new->utf8->convert_blessed; + +{ + my $person = find_type_constraint('Person'); + my $errors = $person->validate({ foo => "bar" }); + + is_deeply( + $JSON->decode($JSON->encode($errors)), + { + errors => { + id => "invalid value undef for 'id'", + name => "invalid value undef for 'name'", + title => "invalid value undef for 'title'", + }, + extra_data => { + foo => "bar", + }, + }, + "error objects can be encoded as json" + ); +} + +done_testing; -- cgit v1.2.3