summaryrefslogtreecommitdiffstats
path: root/t/maybe-doctype.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-15 17:43:28 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-15 17:43:51 -0500
commit8a4a17246fd4b2192fd9dac5d2380c09c666b5ee (patch)
tree9121dd79a1ba947f11f008622d7220132e67c397 /t/maybe-doctype.t
parent0bc360fa3c2e5a85a7110b62b74b1bfb9be284dd (diff)
downloadmoosex-validation-doctypes-8a4a17246fd4b2192fd9dac5d2380c09c666b5ee.tar.gz
moosex-validation-doctypes-8a4a17246fd4b2192fd9dac5d2380c09c666b5ee.zip
add maybe_doctype
Diffstat (limited to 't/maybe-doctype.t')
-rw-r--r--t/maybe-doctype.t75
1 files changed, 75 insertions, 0 deletions
diff --git a/t/maybe-doctype.t b/t/maybe-doctype.t
new file mode 100644
index 0000000..5d15365
--- /dev/null
+++ b/t/maybe-doctype.t
@@ -0,0 +1,75 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Moose::Util::TypeConstraints 'find_type_constraint';
+
+use MooseX::Validation::Doctypes;
+
+doctype 'Person' => {
+ id => 'Str',
+ name => maybe_doctype({
+ first => 'Str',
+ last => 'Str',
+ }),
+ 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 => $person->doctype->{name}, title => 'Str' },
+ "got the right doctype"
+ );
+ is_deeply(
+ $person->doctype->{name}->doctype,
+ { first => 'Str', last => '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");
+ }
+
+ {
+ my $errors = $person->validate({
+ id => '17382-QA',
+ title => 'CIO'
+ });
+ is($errors, undef, "no errors");
+ }
+}
+
+
+done_testing;