From 2174fd7705d465d46743dd4b2113cc98bb717e04 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 15 Oct 2012 17:28:17 -0500 Subject: make nesting doctypes work --- t/nested.t | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 t/nested.t (limited to 't/nested.t') diff --git a/t/nested.t b/t/nested.t new file mode 100644 index 0000000..67f941b --- /dev/null +++ b/t/nested.t @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Moose::Util::TypeConstraints 'find_type_constraint'; + +use MooseX::Validation::Doctypes; + +doctype 'Name' => { + first => 'Str', + last => 'Str', +}; + +doctype 'Person' => { + id => 'Str', + name => 'Name', + title => 'Str', +}; + +{ + my $person = find_type_constraint('Person'); + isa_ok($person, 'Moose::Meta::TypeConstraint'); + isa_ok($person, 'MooseX::Meta::TypeConstraint::Doctype'); + + is_deeply( + $person->doctype, + { id => 'Str', name => 'Name', title => 'Str' }, + "got the right doctype" + ); + + { + my $errors = $person->validate({ + id => '17382-QA', + name => { + first => 'Bob', + last => 'Smith', + }, + title => 'CIO' + }); + is($errors, undef, "no errors"); + } + + { + my $errors = $person->validate({ + id => '17382-QA', + name => { + first => [], + last => 'Smith', + }, + title => 'CIO', + }); + isa_ok($errors, 'MooseX::Validation::Doctypes::Errors'); + is_deeply( + $errors->errors, + { name => { first => "invalid value [ ] for 'name.first'" } }, + "got the right errors" + ); + is($errors->extra_data, undef, "no errors"); + } +} + +done_testing; -- cgit v1.2.3-54-g00ecf