No join pruning on a SINGLE TABLE FROM CLAUSE
[dbsrgits/DBIx-Class.git] / t / cdbi / 11-triggers.t
CommitLineData
510ca912 1use strict;
2use Test::More;
3
50891152 4use lib 't/cdbi/testlib';
510ca912 5use Film;
6
7sub create_trigger2 { ::ok(1, "Running create trigger 2"); }
8sub delete_trigger { ::ok(1, "Deleting " . shift->Title) }
9
10sub pre_up_trigger {
6a3bf251 11 $_[0]->_attribute_set(numexplodingsheep => 1);
12 ::ok(1, "Running pre-update trigger");
510ca912 13}
14sub pst_up_trigger { ::ok(1, "Running post-update trigger"); }
15
16sub default_rating { $_[0]->Rating(15); }
17
1543db24 18Film->add_trigger(before_create => \&default_rating);
19Film->add_trigger(after_create => \&create_trigger2);
20Film->add_trigger(after_delete => \&delete_trigger);
21Film->add_trigger(before_update => \&pre_up_trigger);
22Film->add_trigger(after_update => \&pst_up_trigger);
510ca912 23
24ok(
6a3bf251 25 my $ver = Film->create({
26 title => 'La Double Vie De Veronique',
27 director => 'Kryzstof Kieslowski',
510ca912 28
6a3bf251 29 # rating => '15',
30 numexplodingsheep => 0,
31 }
32 ),
33 "Create Veronique"
510ca912 34);
35
36is $ver->Rating, 15, "Default rating";
37is $ver->NumExplodingSheep, 0, "Original sheep count";
38ok $ver->Rating('12') && $ver->update, "Change the rating";
39is $ver->NumExplodingSheep, 1, "Updated object's sheep count";
40is + (
6a3bf251 41 $ver->db_Main->selectall_arrayref(
42 'SELECT numexplodingsheep FROM '
43 . $ver->table
44 . ' WHERE '
45 . $ver->primary_column . ' = '
46 . $ver->db_Main->quote($ver->id))
510ca912 47)->[0]->[0], 1, "Updated database's sheep count";
48ok $ver->delete, "Delete";
49
50{
8273e845 51 Film->add_trigger(before_create => sub {
6a3bf251 52 my $self = shift;
53 ok !$self->_attribute_exists('title'), "PK doesn't auto-vivify";
54 });
55 Film->create({director => "Me"});
510ca912 56}
d9bd5195 57
58done_testing;