Fix silent failures on autoinc PK without an is_auto_increment attribute
[dbsrgits/DBIx-Class.git] / t / cdbi / copy.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat';
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use lib 't/cdbi/testlib';
10
11 {
12     package # hide from PAUSE
13         MyFilm;
14
15     use base 'DBIC::Test::SQLite';
16     use strict;
17
18     __PACKAGE__->set_table('Movies');
19     __PACKAGE__->columns(All => qw(id title));
20
21     # Disables the implicit autoinc-on-non-supplied-pk behavior
22     # (and the warning that goes with it)
23     # This is the same behavior as it was pre 0.082900
24     __PACKAGE__->column_info('id')->{is_auto_increment} = 0;
25
26     sub create_sql {
27         return qq{
28                 id              INTEGER PRIMARY KEY AUTOINCREMENT,
29                 title           VARCHAR(255)
30         }
31     }
32 }
33
34 my $film = MyFilm->create({ title => "For Your Eyes Only" });
35 ok $film->id;
36
37 my $new_film = $film->copy;
38 ok $new_film->id;
39 isnt $new_film->id, $film->id, "copy() gets new primary key";
40
41 $new_film = $film->copy(42);
42 is $new_film->id, 42, "copy() with new id";
43
44 done_testing;