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