fix bogus tests
[dbsrgits/DBIx-Class-Journal.git] / t / 03populate.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 BEGIN {
6     eval "use DBD::SQLite; use SQL::Translator";
7     plan $@
8         ? ( skip_all => 'needs DBD::SQLite and SQL::Translator for testing' )
9         : ( tests => 11 );
10 }
11
12 use lib qw(t/lib);
13 use DBICTest;
14
15 # connect to db and deploy only the original db schema, not journal schema
16 my $schema = DBICTest->init_schema(no_populate => 1, no_deploy => 1);
17
18 ok($schema, 'Created a Schema');
19 $schema->deploy;
20
21 # check we have no journal
22 my $count = eval {
23     $schema->_journal_schema->resultset('ChangeLog')->count;
24 };
25 my $e = $@;
26
27 is( $count, undef, 'no count' );
28 like( $e, qr/table.*changelog/, 'missing table error' );
29
30 # insert two rows -not- in txn
31 $schema->storage->dbh_do(sub {
32    my $dbh = $_[1];
33    $dbh->do($_) for (
34      "INSERT INTO artist ( name ) VALUES ('Fred Bloggs A' )",
35      "INSERT INTO artist ( name ) VALUES ('Fred Bloggs B' )"
36    );
37 });
38
39 # create the journal
40 $schema->journal_schema_deploy();
41
42 # check it is empty
43 $count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
44
45 is( $@, '', "no error" );
46 is( $count, 0, "count is 0 (changelog)" );
47
48 # run populate
49 $schema->prepopulate_journal();
50
51 # check there is only one changeset
52 $count = eval { $schema->_journal_schema->resultset('ChangeSet')->count };
53
54 is( $@, '', "no error" );
55 is( $count, 1, "count is 1 (changeset)" );
56
57 # check it contains two inserts
58 $count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
59
60 is( $@, '', "no error" );
61 is( $count, 2, "count is 2 (changelog)" );
62
63 # check audit log has two rows for two inserts
64 $count = eval { $schema->_journal_schema->resultset('ArtistAuditLog')->count };
65
66 is( $@, '', "no error" );
67 is( $count, 2, "count is 2 (auditlog)" );
68