10 eval "use DBD::SQLite";
12 ? ( skip_all => 'needs DBD::SQLite for testing' )
16 my $schema = DBICTest->init_schema(no_populate => 1);
18 ok($schema, 'Created a Schema');
19 isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB', 'Actually have a schema object for the journaling');
20 isa_ok($schema->_journal_schema->source('CDAuditHistory'), 'DBIx::Class::ResultSource', 'CDAuditHistory source exists');
21 isa_ok($schema->_journal_schema->source('ArtistAuditLog'), 'DBIx::Class::ResultSource', 'ArtistAuditLog source exists');
24 my $new_cd = $schema->txn_do( sub {
25 my $current_changeset = $schema->_journal_schema->_current_changeset;
26 ok( $current_changeset, "have a current changeset" );
28 $artist = $schema->resultset('Artist')->create({
29 name => 'Fred Bloggs',
33 is( $current_changeset, $schema->_journal_schema->_current_changeset, "nested txn doesn't create a new changeset" );
34 return $schema->resultset('CD')->create({
35 title => 'Angry young man',
41 isa_ok($new_cd, 'DBIx::Class::Journal', 'Created CD object');
43 is( $schema->_journal_schema->_current_changeset, undef, "no current changeset" );
44 eval { $schema->_journal_schema->current_changeset };
45 ok( $@, "causes error" );
47 my $search = $schema->_journal_schema->resultset('CDAuditLog')->search();
48 ok($search->count, 'Created an entry in the CD audit log');
50 $schema->txn_do( sub {
55 is($new_cd->year, 2003, 'Changed year to 2003');
56 my $cdah = $schema->_journal_schema->resultset('CDAuditHistory')->search();
57 ok($cdah->count, 'Created an entry in the CD audit history');
59 $schema->txn_do( sub {
60 $schema->resultset('CD')->create({
67 $schema->txn_do( sub {
71 my $alentry = $search->find({ map { $_ => $new_cd->get_column($_) } $new_cd->primary_columns });
72 ok(defined($alentry->deleted), 'Deleted set in audit_log');
74 $schema->changeset_user(1);
75 $schema->txn_do( sub {
76 $schema->resultset('CD')->create({
77 title => 'Something 2',
83 ok($search->count > 1, 'Created an second entry in the CD audit history');
85 my $cset = $schema->_journal_schema->resultset('ChangeSet')->find(5);
86 is($cset->user_id, 1, 'Set user id for 5th changeset');
88 $schema->changeset_session(1);
89 $schema->txn_do( sub {
90 $schema->resultset('CD')->create({
91 title => 'Something 3',
97 my $cset2 = $schema->_journal_schema->resultset('ChangeSet')->find(6);
98 is($cset2->session_id, 1, 'Set session id for 6th changeset');