File: db_has_one.t

package info (click to toggle)
libhtml-formhandler-model-dbic-perl 0.29-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: perl: 1,873; sql: 259; makefile: 14
file content (64 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strict;
use warnings;

use Test::More;
use lib 't/lib';

use BookDB::Schema;

my $schema = BookDB::Schema->connect('dbi:SQLite:t/db/book.db');
my $user = $schema->resultset('User')->find(1);

{
    package Options::Field;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler::Field::Compound';

    has_field 'options_id' => ( type => 'PrimaryKey' );
    has_field 'option_one';
    has_field 'option_two';
    has_field 'option_three';
}

{
   package Form::User;
   use HTML::FormHandler::Moose;
   extends 'HTML::FormHandler::Model::DBIC';

   has_field 'user_name';
   has_field 'occupation';

   has_field 'options' => ( type => '+Options::Field' );

}

my $form = Form::User->new;
ok( $form, 'get db form');
$form->process( item => $user, params => {} );

my $expected = {
    user_name => 'jdoe',
    occupation => 'management',
    options => {
        options_id => 1,
        option_one => 'blue',
        option_two => 'red',
        option_three => 'green',
    }
};

is_deeply( $form->value, $expected, 'got expected values' );

$expected->{options}->{option_one} = 'yellow';
$form->process( item => $user, params => $expected );
is_deeply( $form->value, $expected, 'got changed expected values' );
$user->discard_changes;

my $option_one = $user->options->option_one;
is( $option_one, 'yellow', 'user options changed' );

$expected->{options}->{option_one} = 'blue';
$form->process( item => $user, params => $expected );


done_testing;