/t/circular_refs.t

http://github.com/gshank/html-formhandler · Raku · 49 lines · 42 code · 7 blank · 0 comment · 1 complexity · f68c961a752988f869a7c459e50c51b7 MD5 · raw file

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