From 7009c45d832016e6cc8f95371daddf0d327ba4e0 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Wed, 19 Oct 2016 17:13:10 -0700 Subject: [PATCH] failing test for new Text validation issue --- t/fields/text-subclass.t | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 t/fields/text-subclass.t diff --git a/t/fields/text-subclass.t b/t/fields/text-subclass.t new file mode 100644 index 00000000..8df69aff --- /dev/null +++ b/t/fields/text-subclass.t @@ -0,0 +1,47 @@ +use strict; +use warnings; +use Test::More; + +{ + package MyApp::Field::DuplicateText; + use HTML::FormHandler::Moose; + extends 'HTML::FormHandler::Field::Text'; + + apply [ { + transform => sub { + my $value = shift; + # collapses down to a single entry if passed a list where all + # values are identical + return $value->[0] if + defined $value + and ref $value eq 'ARRAY' + and not grep { $value->[0] ne $_ } @$value; + return $value; + }, + }]; +} + + +# tests the TextCSV field +{ + package MyApp::Form::Test; + use HTML::FormHandler::Moose; + extends 'HTML::FormHandler'; + + has_field 'foo' => ( type => '+MyApp::Field::DuplicateText' ); + has_field 'bar' => ( type => '+MyApp::Field::DuplicateText' ); +} + +my $form = MyApp::Form::Test->new; +ok( $form ); +$form->process( params => { foo => '1', bar => ['2,2'] } ); + +TODO: { +local $TODO = 'this test broke with commit 0cae37c6'; + +ok($form->validated, 'field of list values validates') + or diag 'got errors: ', explain [ $form->errors_by_name ]; + +} + +done_testing;