9 eval "use DBD::SQLite; use SQL::Translator";
11 ? ( skip_all => 'needs DBD::SQLite and SQL::Translator for testing' )
15 my $schema = DBICTest->init_schema(no_populate => 1);
17 ok($schema, 'Created a Schema');
20 $schema->_journal_schema,
21 'DBIx::Class::Schema::Journal::DB',
22 'Actually have a schema object for the journaling'
26 $schema->_journal_schema->source('CDAuditHistory'),
27 'DBIx::Class::ResultSource',
28 'CDAuditHistory source exists'
32 $schema->_journal_schema->source('ArtistAuditLog'),
33 'DBIx::Class::ResultSource',
34 'ArtistAuditLog source exists'
38 my $new_cd = $schema->txn_do( sub {
39 my $current_changeset = $schema->_journal_schema->_current_changeset;
40 ok( $current_changeset, 'have a current changeset' );
42 $artist = $schema->resultset('Artist')->create({
43 name => 'Fred Bloggs',
49 $schema->_journal_schema->_current_changeset,
50 q{nested txn doesn't create a new changeset}
52 return $schema->resultset('CD')->create({
53 title => 'Angry young man',
61 'DBIx::Class::Journal',
66 $schema->_journal_schema->_current_changeset,
67 undef, 'no current changeset'
69 eval { $schema->_journal_schema->current_changeset };
70 ok( $@, 'causes error' );
72 my $search = $schema->_journal_schema->resultset('CDAuditLog')->search;
73 ok($search->count, 'Created an entry in the CD audit log');
80 is($new_cd->year, 2003, 'Changed year to 2003');
81 my $cdah = $schema->_journal_schema->resultset('CDAuditHistory')->search;
82 ok($cdah->count, 'Created an entry in the CD audit history');
84 $schema->txn_do( sub {
85 $schema->resultset('CD')->create({
93 my %id = map { $_ => $new_cd->get_column($_) } $new_cd->primary_columns;
95 $schema->txn_do( sub {
100 my $alentry = $search->find(\%id);
101 ok($alentry, 'got log entry');
102 ok(defined($alentry->deleted), 'Deleted set in audit_log');
104 $alentry->deleted->id, '>', $alentry->created->id,
105 'deleted is after created'
109 $new_cd = $schema->txn_do( sub {
110 $schema->resultset('CD')->create({
119 my $alentry = $search->find(\%id);
120 ok($alentry, 'got log entry');
121 ok(defined($alentry->deleted), 'Deleted set in audit_log');
123 $alentry->deleted->id, '<', $alentry->created->id,
124 'deleted is before created (recreated)'
128 $schema->changeset_user(1);
129 $schema->txn_do( sub {
130 $schema->resultset('CD')->create({
131 title => 'Something 2',
137 ok($search->count > 1, 'Created an second entry in the CD audit history');
139 my $cset = $schema->_journal_schema->resultset('ChangeSet')->find(6);
140 is($cset->user_id, 1, 'Set user id for 6th changeset');
142 $schema->changeset_session(1);
143 $schema->txn_do( sub {
144 $schema->resultset('CD')->create({
145 title => 'Something 3',
151 my $cset2 = $schema->_journal_schema->resultset('ChangeSet')->find(7);
152 is($cset2->session_id, 1, 'Set session id for 7th changeset');