946b0606a0ea36aed8c4a9ed4bbbed7dad8308d9
[dbsrgits/DBIx-Class.git] / t / discard_changes_in_DESTROY.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use warnings;  
5
6 use Test::More;
7 use lib qw(t/lib);
8 use DBICTest;
9
10 my $schema = DBICTest->init_schema();
11
12 plan tests => 1;
13
14 {
15     my @warnings;
16     local $SIG{__WARN__} = sub { push @warnings, @_; };
17     {
18         # Test that this doesn't cause infinite recursion.
19         local *DBICTest::Artist::DESTROY;
20         local *DBICTest::Artist::DESTROY = sub { $_[0]->discard_changes };
21         
22         my $artist = $schema->resultset("Artist")->create( { 
23             artistid    => 10,
24             name        => "artist number 10",
25         });
26         
27         $artist->name("Wibble");
28         
29         print "# About to call DESTROY\n";
30     }
31     is_deeply \@warnings, [];
32 }