don't warn unnecessarily
[dbsrgits/DBIx-Class-Journal.git] / t / 01test.t
CommitLineData
b5851590 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7use Data::Dumper;
8
9BEGIN {
10 eval "use DBD::SQLite";
11 plan $@
12 ? ( skip_all => 'needs DBD::SQLite for testing' )
faa4607e 13 : ( tests => 14 );
b5851590 14}
15
16my $schema = DBICTest->init_schema(no_populate => 1);
17
18ok($schema, 'Created a Schema');
c5fba518 19isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB', 'Actually have a schema object for the journaling');
20isa_ok($schema->_journal_schema->source('CDAuditHistory'), 'DBIx::Class::ResultSource', 'CDAuditHistory source exists');
21isa_ok($schema->_journal_schema->source('ArtistAuditLog'), 'DBIx::Class::ResultSource', 'ArtistAuditLog source exists');
22
faa4607e 23{
24 my $count = eval {
25 warn $schema->_journal_schema->resultset('ArtistAuditLog')->count;
26 };
27 my $e = $@;
28
29 is( $count, undef, "no count" );
30 like( $e, qr/table.*artist_audit_log/i, "missing table error" );
31}
32
33$schema->journal_schema_deploy();
34
1e996809 35my $artist;
f4f0b7c9 36my $new_cd = $schema->txn_do( sub {
1e996809 37 $artist = $schema->resultset('Artist')->create({
f3602465 38 name => 'Fred Bloggs',
39 });
f4f0b7c9 40 return $schema->resultset('CD')->create({
41 title => 'Angry young man',
f3602465 42 artist => $artist,
f4f0b7c9 43 year => 2000,
c5fba518 44 });
f4f0b7c9 45});
c5fba518 46isa_ok($new_cd, 'DBIx::Class::Journal', 'Created CD object');
47
48my $search = $schema->_journal_schema->resultset('CDAuditLog')->search();
49ok($search->count, 'Created an entry in the CD audit log');
50
1e996809 51$schema->txn_do( sub {
52 $new_cd->year(2003);
53 $new_cd->update;
54} );
55
56is($new_cd->year, 2003, 'Changed year to 2003');
57my $cdah = $schema->_journal_schema->resultset('CDAuditHistory')->search();
58ok($cdah->count, 'Created an entry in the CD audit history');
59
60$schema->txn_do( sub {
61 $schema->resultset('CD')->create({
62 title => 'Something',
63 artist => $artist,
64 year => 1999,
65 });
66} );
67
68$schema->txn_do( sub {
69 $new_cd->delete;
70} );
71
72my $alentry = $search->find({ ID => $new_cd->get_column($new_cd->primary_columns) });
73ok(defined($alentry->deleted), 'Deleted set in audit_log');
b5851590 74
ec16e73a 75$schema->changeset_user(1);
76$schema->txn_do( sub {
77 $schema->resultset('CD')->create({
78 title => 'Something 2',
79 artist => $artist,
80 year => 1999,
81 });
82} );
83
84ok($search->count > 1, 'Created an second entry in the CD audit history');
85
86my $cset = $schema->_journal_schema->resultset('ChangeSet')->find(5);
87is($cset->user_id, 1, 'Set user id for 5th changeset');
88
89$schema->changeset_session(1);
90$schema->txn_do( sub {
91 $schema->resultset('CD')->create({
92 title => 'Something 3',
93 artist => $artist,
94 year => 1999,
95 });
96} );
97
98my $cset2 = $schema->_journal_schema->resultset('ChangeSet')->find(6);
99is($cset2->session_id, 1, 'Set session id for 6th changeset');
100