File: has_many_repeatable_new_date.t

package info (click to toggle)
libhtml-formfu-model-dbic-perl 0.06000-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,252 kB
  • ctags: 147
  • sloc: perl: 2,112; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 1,914 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use strict;
use warnings;
use Test::More tests => 9;

use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
use DateTime;

my $form = HTML::FormFu->new;

$form->load_config_file('t/update/has_many_repeatable_new_date.yml');

my $schema = new_schema();

my $master_rs = $schema->resultset('Master');

# filler rows
{
    # user 1
    my $m1 = $master_rs->create( { text_col => 'foo' } );
    
    # schedule 1
    $m1->create_related( 'schedules', {
        date => DateTime->new( year => 2008, month => 7, day => 16 ),
        note => 'a',
    } );
    
    # schedule 2
    $m1->create_related( 'schedules', {
        date => DateTime->new( year => 2008, month => 7, day => 17 ),
        note => 'b',
    } );
}

# rows we're going to use
{
    # user 2
    my $m2 = $master_rs->create( { text_col => 'orig text', } );
    
    # schedule 3
    $m2->create_related( 'schedules', {
        date => DateTime->new( year => 2008, month => 7, day => 18 ),
        note => 'c',
    } );
}

{
    $form->process( {
            'text_col'               => 'new text',
            'count'                  => 1,
            'schedules_1.id'         => 3,
            'schedules_1.date_day'   => '19',
            'schedules_1.date_month' => '07',
            'schedules_1.date_year'  => '2008',
            'schedules_1.note'       => 'hi',
        } );

    ok( $form->submitted_and_valid );

    my $row = $schema->resultset('Master')->find(2);

    $form->model->update($row);
}

{
    my $user = $schema->resultset('Master')->find(2);

    is( $user->text_col, 'new text' );

    my @schedule = $user->schedules->all;

    is( scalar @schedule, 1 );

    is( $schedule[0]->id, 3 );
    
    my $date = $schedule[0]->date;
    
    isa_ok( $date, 'DateTime' );
    
    is( $date->year,  2008 );
    is( $date->month, 7 );
    is( $date->day,   19 );
    
    is( $schedule[0]->note, 'hi' );
}