should use hashrefinflator
[dbsrgits/DBIx-Class-Journal.git] / t / 03populate.t
CommitLineData
e32a5dbb 1use strict;
2use warnings;
3
4use Test::More;
5BEGIN {
6 eval "use DBD::SQLite; use SQL::Translator";
7 plan $@
8 ? ( skip_all => 'needs DBD::SQLite and SQL::Translator for testing' )
067f1fd1 9 : ( tests => 11 );
e32a5dbb 10}
11
12use lib qw(t/lib);
13use DBICTest;
14
15# connect to db and deploy only the original db schema, not journal schema
16my $schema = DBICTest->init_schema(no_populate => 1, no_deploy => 1);
e32a5dbb 17
18ok($schema, 'Created a Schema');
1891bb5f 19$schema->deploy;
e32a5dbb 20
21# check we have no journal
22my $count = eval {
23 $schema->_journal_schema->resultset('ChangeLog')->count;
24};
25my $e = $@;
26
27is( $count, undef, 'no count' );
28like( $e, qr/table.*changelog/, 'missing table error' );
29
30# insert two rows -not- in txn
067f1fd1 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});
e32a5dbb 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
45is( $@, '', "no error" );
c34c1387 46is( $count, 0, "count is 0 (changelog)" );
e32a5dbb 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
54is( $@, '', "no error" );
55is( $count, 1, "count is 1 (changeset)" );
56
57# check it contains two inserts
58$count = eval { $schema->_journal_schema->resultset('ChangeLog')->count };
59
60is( $@, '', "no error" );
61is( $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
66is( $@, '', "no error" );
67is( $count, 2, "count is 2 (auditlog)" );
68