PageRenderTime 69ms CodeModel.GetById 43ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/t/circular_refs.t

http://github.com/gshank/html-formhandler
text | 49 lines | 42 code | 7 blank | 0 comment | 0 complexity | f68c961a752988f869a7c459e50c51b7 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4use Test::Memory::Cycle;
 5
 6{
 7   package My::RepeatableForm;
 8   use HTML::FormHandler::Moose;
 9   extends 'HTML::FormHandler';
10
11   has '+name' => ( default => 'testform' );
12   has_field 'reqname' => ( required => 1 );
13   has_field 'entries' => (
14        type             => 'Repeatable',
15        required         => 1,
16        required_message => 'Request without entries not accepted'
17    );
18    has_field 'entries.rule_index' => ( type => 'PrimaryKey' );
19    has_field 'entries.foo' => (
20        type     => 'Text',
21        required => 1,
22    );
23    has_field 'entries.bar' => (
24        type     => 'Text',
25        required => 1,
26    );
27    has_field 'some_select' => ( type => 'Select', inactive => 1 );
28
29    sub update_model {
30        my $self = shift;
31        my $value = $self->field('some_select')->value;
32    }
33}
34
35my $form = new_ok( 'My::RepeatableForm' );
36
37my $params = {
38    reqname => 'Testrequest',
39    'entries.1.foo' => 'test1',
40    'entries.1.bar' => 'test1',
41    'entries.2.foo' => 'test2',
42    'entries.2.bar' => 'test2',
43};
44memory_cycle_ok( $form, 'form has no memory cycles before process' );
45ok( $form->process( params => $params ), 'form processed ok' );
46memory_cycle_ok( $form, 'form has no memory cycles after process' );
47
48done_testing;
49